Advertisement
Sungmingamerpro13

New DialogueScript

Dec 10th, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 3.14 KB | None | 0 0
  1. local Message = game.ReplicatedStorage:WaitForChild("Message")
  2. local Image = Message:WaitForChild("SpeakerImage")
  3. local PlayerImage = Message:WaitForChild("PlayerImage")
  4. local Speaker = Message:WaitForChild("SpeakerName")
  5. local PlayerName = Message:WaitForChild("PlayerName")
  6. local HideDialogueEvent = Message:WaitForChild("HideDialogueEvent")
  7.  
  8. local player = game.Players.LocalPlayer
  9. local DialogueFrame = player.PlayerGui:WaitForChild("DialogueGui").DialogueFrame
  10.  
  11. -- Create a camera instance and attach it to the DialogueFrame
  12. local camera = Instance.new("Camera")
  13. camera.Parent = DialogueFrame
  14.  
  15. -- Function to update the character display (only head and accessories)
  16. local function UpdateCharacter(character)
  17.     local worldModel = DialogueFrame.PlayerImage.Icon.WorldModel
  18.  
  19.     -- Clear existing parts in the WorldModel
  20.     for _, child in pairs(worldModel:GetChildren()) do
  21.         if child:IsA("BasePart") or child:IsA("Accessory") then
  22.             child:Destroy()
  23.         end
  24.     end
  25.  
  26.     -- Clone only the head and accessories from the character
  27.     for _, child in pairs(character:GetChildren()) do
  28.         if child:IsA("Accessory") or (child:IsA("BasePart") and child.Name == "Head") then
  29.             local clonedChild = child:Clone()
  30.             clonedChild.Parent = worldModel
  31.         end
  32.     end
  33.  
  34.     -- Set the camera to focus on the head
  35.     local head = worldModel:FindFirstChild("Head")
  36.     if head then
  37.         camera.CFrame = head.CFrame * CFrame.new(0, 0.2, -2) * CFrame.Angles(0, math.rad(180), 0)
  38.         DialogueFrame.PlayerImage.Icon.CurrentCamera = camera
  39.     else
  40.         warn("Head not found in character!")
  41.     end
  42. end
  43.  
  44. -- Hide the dialogue frame when the event is triggered
  45. HideDialogueEvent.OnClientEvent:Connect(function()
  46.     DialogueFrame:TweenPosition(UDim2.new(0.55, 0, -1, 0))
  47. end)
  48.  
  49. -- Update the dialogue text when the message changes
  50. Message:GetPropertyChangedSignal("Value"):Connect(function()
  51.     DialogueFrame.Dialogue.Text = Message.Value
  52.     script.DialogueSound:Play()
  53. end)
  54.  
  55. -- Update the speaker and character display when the speaker changes
  56. Speaker:GetPropertyChangedSignal("Value"):Connect(function()
  57.     DialogueFrame:TweenPosition(UDim2.new(0.55, 0, 0.139, 0))
  58.     print("New Speaker: " .. Speaker.Value)
  59.  
  60.     local character = workspace:FindFirstChild(Image.Value)
  61.     if character then
  62.         UpdateCharacter(character)
  63.     else
  64.         warn("Character not found in workspace: " .. Image.Value)
  65.     end
  66.     DialogueFrame.PlayerImage.Icon.Visible = true
  67.     DialogueFrame.PlayerImage.PlayerIcon.Visible = false
  68.     DialogueFrame.PlayerImage.Icon.nameLabel.Visible = true
  69.     DialogueFrame.PlayerImage.PlayerIcon.nameLabel.Visible = false
  70.     DialogueFrame.PlayerImage.Icon.nameLabel.Text = Speaker.Value
  71. end)
  72.  
  73. PlayerName:GetPropertyChangedSignal("Value"):Connect(function()
  74.     DialogueFrame:TweenPosition(UDim2.new(0.55, 0, 0.139, 0))
  75.     print("New Speaker: " .. PlayerName.Value)
  76.    
  77.     DialogueFrame.PlayerImage.Icon.Visible = false
  78.     DialogueFrame.PlayerImage.PlayerIcon.Visible = true
  79.     DialogueFrame.PlayerImage.Icon.nameLabel.Visible = false
  80.     DialogueFrame.PlayerImage.PlayerIcon.nameLabel.Visible = true
  81.     DialogueFrame.PlayerImage.PlayerIcon.Image = PlayerImage.Value
  82.     DialogueFrame.PlayerImage.PlayerIcon.nameLabel.Text = PlayerName.Value
  83. end)
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement