I want to try and insert a dialog, and a sound into a player when they click a button. I'm not sure how to do this. This was my attempt (it doesn't work and I don't really understand the whole :GetPlayer stuff yet)
local button = script.Parent local name = game.Players:GetFullName(game.Players:GetPlayerFromCharacter) local dialog = game.ServerStorage.Dialog:Clone() local talk = button.Talk:Clone() button.ClickDetector.MouseClick:Connect(function() local playerw = name dialog.Parent = playerw.Head talk.Parent = playerw.Head playerw.Head.Talk.Playing = true end)
Sorry for how messy it is, I was just lost. I really have no clue on this one.
This is not that complicated. All you need is the parameter playerWhoClicked, which is built into Roblox. If your having trouble, make sure to take a look at the DevHub.
Note: Considering you haven't guessed already, the parameter playerWhoClicked is literally the player who clicked.
https://developer.roblox.com/en-us/api-reference/event/ClickDetector/MouseClick
Anyways, here is the code :
button.ClickDetector.MouseClick:Connect(function(playerWhoClicked) local dialog = game.ServerStorage.Dialog:Clone() local talk = button.Talk:Clone() talk.Parent = playerWhoClicked.Character.Head dialog.Parent = playerWhoClicked.Character.Head talk.Playing = true end)
I'm not sure if this code works, but if it doesn't, please contact me back and I will be able to help some more.