I am making a message that will only appear to the person who clicked the button but it won't work could someone help me fix it? Heres the code:
script.Parent.ClickDetector.mouseClick:connect(onClicked) function onClicked() local message = Instance.new('Message', game.Players.LocalPlayer.PlayerGui) -- Insert a new message in the Workspace. message.Text = "Admins Only in this room" -- Set the text of the message wait(5) message:Destroy() -- Remove the message after 5 seconds. end
First of all, the event that fires from the ClickDetector when a player clicks on it is MouseClick
, not mouseClick
.
Secondly, at line 1, you can see that you've connected the event to the onClicked
function, but the script doesn't know what onClicked
is yet until it is defined line 3. So, that's another reason it will break.
Lastly, you used game.Players.LocalPlayer
. LocalPlayer
only works in LocalScripts run by the client, and not the ROBLOX game server. Instead, you can use an argument passed by the MouseClick
of the ClickDetector like this:
function onClicked(playerWhoClicked) print(playerWhoClicked.Name.." clicked this!") end