Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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.

0
I know this is kind of a stupid question i just don't know how to do that Just_Moop 27 — 5y
0
there's no real need to do that, u could just do this, function(andputhereanything, that's gonna be ur player) BANSA168 15 — 5y
0
wow BANSA168 so helpful totally understand that YTEqrypted_Eqrypto -16 — 5y
0
Yeah i just found that out thanks so much. Just_Moop 27 — 5y
View all comments (2 more)
0
I don't think this question deserves a downvote, he provided code, he just didn't know how to get the player OBenjOne 190 — 5y
0
Also whoever gave that downvote should provide a reson next time OBenjOne 190 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question