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

Error when message is only showing to the player who clicked the button?

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


1 answer

✓ Accepted answer

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

1 comment

0

Thanks

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