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

How to make a textbutton return a player?

I understand that if you click a brick with the function

script.Parent.ClickDetector:connect(function(p)
	player = p.Parent
end)

But how would I get player in a textbutton on a surfacegui? I can't work it out. Thanks.

1 answer

For a surface gui it would have to be a local script put in starterpack/startergui. So we will be able to use localplayer. Example:

local textbutton = workspace.Part.SurfaceGui.TextButton

textbutton.MouseButton1Click:connect(function()
	print(game.Players.LocalPlayer)
	plr = game.Players.LocalPlayer
end)

That should work, hope it helped!

8 comments

0

No, because the script is inside the surfacegui.

1

What do you mean the script is inside the surfacegui, when the button is clicked, you can get the localplayer from the local script that you put in starterpack/startergui, and if you need that player in a serverscript, then you can use RemoteEvents... that's the only way it's possible.

0

The script is inside the surfacegui. What's so confusing about that? And I don't want the script in StarterPack/GUI. It needs to be in that part for that model.

0

Invite me to a party on roblox, so I can better explain...

0

@Traigla, this is the only way you can get it, and if you want to do anything with the script that is going to be under the brick, that would be a server script, and you can send information to that from the local script using a RemoteEvent, abs is totally right.

0

You need to adornee the surface GUI to the actual part, but keep the real Gui inside the player

0

I think triagla is pointing out that the local script is under the brick or surfacegui, and it isn't getting put into the player in game.Players

0

Thats why you have to do what I said earlier, @dragon

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