Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I insert things into a certain player who clicks a button?

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.

6 comments

0

I know this is kind of a stupid question i just don't know how to do that

0

there's no real need to do that, u could just do this, function(andputhereanything, that's gonna be ur player)

0

wow BANSA168 so helpful totally understand that

0

Yeah i just found that out thanks so much.

0

I don't think this question deserves a downvote, he provided code, he just didn't know how to get the player

0

Also whoever gave that downvote should provide a reson next time

2 answers

✓ Accepted answer

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.

Just type after (function(Player) and that is your player

This discussion is preserved as it was. New answers, comments, and votes are closed.