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

Is there any way to reference the player when the player clicks a TextButton?

Hi everyone, I was building a GUI System and I was wondering that is there a function that lets you reference a player when the player clicks on a TextButton?

script.Parent.MouseButton1Click:Connect(function(click)
	local obj = script.Parent.Parent.Parent.Database
	local newobj = Instance.new("StringValue", obj)
	newobj.Name = click.Name --(everything works until here, where "click" is not valid due to the event not having a valid variable)
	
	
	
end)	

Looking forward to your responses!

2 answers

✓ Accepted answer

No.. This is also not needed.

MouseButton1Click has no args. To get the player simply use localplayer

local player = game.Players.LocalPlayer

This only works in local scripts as there is a copy of the script for every player (and it knows who the owner is)!!

(You probably confused it with MouseClick wich has a 'click' arg.)

Actually, Every player has their own GUIs in their Character Folder. You don't have to hook who's clicking the GUI since it only exists in his/her own Folder.

local playerName = game.Players.LocalPlayer;

script.Parent.MouseButton1Click:Connect(function()
    local obj = script.Parent.Parent.Parent.Database
    local newobj = Instance.new("StringValue", obj)
    newobj.Name = playerName 


end)    


2 comments

0

This is actually a surfaceGui, and not a ScreenGui, if it was a ScreenGui, I'd knew what to do.

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