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!
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)