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

finding the name of a player who clicked a surfacegui button through different ways?

script.Parent.MouseButton1Click:Connect(function(plr)

print(plr.Name)

end)

this script of course cant find the name of the player unless the surfacegui is a decendant of the client. however I cant add the surfacegui by localscript as some people say I should do because the gui needs to be part of a model rather than being cloned from startergui. is there a different way for me to get the player who clicked a gui? such as the players character name or a string value with the players name in it?

1 answer

✓ Accepted answer

There is, what I'd do is start with a localscript, now, when the player clicks the surface gui, fire to the server like so.

script.Parent.MouseButton1Click:Connect(function()
		game.ReplicatedStorage.Event:FireServer(ARGUMENTS HERE)
end)

Now that that is out of the way, create a server script, can be anywhere so long as the server can recognize it when the Event is called

Inside of that script, create the Event and then print the player's name which is always the FIRST ARGUMENT in the event

game.ReplicatedStorage.Event.OnServerEvent:Connect(function(player,ARGUMENTS)
       print(player.Name.." has clicked the surfacegui!")
end)

Now, due to this being in the server, this goes for ALL people in game, so in theory, if you wanted to change the surfacegui's Textlabel 's text to the player who clicked the button's name, all you'd need to do is.

game.ReplicatedStorage.Event.OnServerEvent:Connect(function(player,ARGUMENTS) 
				<Surfacegui destination>..TextLabel.Text = player.Name
end)

In another example, you could FireAllClients so everyone's client can see the player who cloicked the textbutton as well.

But since you are stating that this is a surface gui, I'll assume that you won't need to FireAllClients so I'll leave it at that considering unlike a player's screengui that is on a client side only, you can change a Surfacegui through the server.

3 comments

0

I apologize for the terrible examples however, I misread your question just a tad bit. But my answer still stands. It should be quite easy to tweak that setup to fix your little problem.

0

heres what I put for the local script: script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent.Parent.Parent.OwnerFilter:FireServer() end) the button1click event wont fire, I even tried just having it print something after clicking the button but it wont even do that.

0

I decided to just use a clickdetector to filter out player names. its not as compact as I would have wanted it to be but oh well.

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