Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

Ad
Log in to vote
0
Answered by 6 years ago

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)    


0
This is actually a surfaceGui, and not a ScreenGui, if it was a ScreenGui, I'd knew what to do. Syntax_404 37 — 6y

Answer this question