CCCPaste

New DialogueScript (LocalScript) SungExetior13RBLX (Sungmin)

local Message = game.ReplicatedStorage:WaitForChild("Message")
local Image = Message:WaitForChild("SpeakerImage")
local Speaker = Message:WaitForChild("SpeakerName")

local player = game.Players.LocalPlayer
local DialogueFrame = player.PlayerGui:WaitForChild("DialogueGui").DialogueFrame

-- Create a camera instance and attach it to the DialogueFrame
local camera = Instance.new("Camera")
camera.Parent = DialogueFrame

-- Variables
DefaultMessageDelayTime = 4
LetterInvertal = 0.05
MessageWaitSigns = {',', '?', '.'}
MessageWaitSignDelay = 1

-- Function to update the character display (only head and accessories)
local function UpdateCharacter(character)
	local worldModel = DialogueFrame.PlayerImage.Icon.WorldModel

	-- Clear existing parts in the WorldModel
	for _, child in pairs(worldModel:GetChildren()) do
		if child:IsA("BasePart") or child:IsA("Accessory") then
			child:Destroy()
		end
	end

	-- Clone only the head and accessories from the character
	for _, child in pairs(character:GetChildren()) do
		if child:IsA("Accessory") or (child:IsA("BasePart") and child.Name == "Head") then
			local clonedChild = child:Clone()
			clonedChild.Parent = worldModel
		end
	end

	-- Set the camera to focus on the head
	local head = worldModel:FindFirstChild("Head")
	if head then
		camera.CFrame = head.CFrame * CFrame.new(0, 0.1, -2) * CFrame.Angles(0, math.rad(180), 0)
		DialogueFrame.PlayerImage.Icon.CurrentCamera = camera
	else
		warn("Head not found in character!")
	end
end

local function Animate(Text, MessageDelayTime)
	for i = 1,#Text,1 do
		DialogueFrame.Dialogue.Text = string.sub(Text,1,i)
		script.DialogueSound:Play()
		for _, L in pairs(MessageWaitSigns) do
			if string.sub(Text,i,i) == L then
				wait(MessageWaitSignDelay)
			end
		end
		wait(LetterInvertal)
	end
	if tonumber(MessageDelayTime) ~= nil then
		wait(MessageDelayTime)
	else
		wait(DefaultMessageDelayTime)
	end
	DialogueFrame:TweenPosition(UDim2.new(0.55, 0, -1, 0))
end

-- Update the dialogue text when the message changes
Message:GetPropertyChangedSignal("Value"):Connect(function()
	DialogueFrame:TweenPosition(UDim2.new(0.55, 0, 0.15, 0))
	Animate(Message.Value)
end)

-- Update the speaker and character display when the speaker changes
Speaker:GetPropertyChangedSignal("Value"):Connect(function()
	print("New Speaker: " .. Speaker.Value)

	local character = workspace:FindFirstChild(Image.Value)
	if character then
		UpdateCharacter(character)
	else
		warn("Character not found in workspace: " .. Image.Value)
	end

	DialogueFrame.PlayerImage.Icon.nameLabel.Text = Speaker.Value
end)