Call the local player in a script

I am making a script that runs a function when the textbutton is clicked. How do I see what player clicked the button? Example below.

function onTouched(hit)
	*my script here*
script.Parent.MouseButton1Click:Connect(ontouched)

I can’t answer this because you say “TextButton is Clicked” but then proceeds to make a .Touched event that is only used in parts, pls explain more.

Oh yea, you’re not going to use too much of ServerScripts on GUIs, so use a LocalScript if you can.

if youre using a TextButton, then i will assume that its a GUI object. in this case, GUI’s are handled on the client side, therefor you can get the player directly from a local script using

local player = game.Players.LocalPlayer

button.MouseButton1Click:connect(function()
  print(player)
end)

I am unable to use a local script as it makes my morph, [This is a morph script] only appear on the client side.

Easy, Use RemoveEvents

are u sending a remote event to the server when the player clicks the button?

No, I dont know how to use remote events all to well.

then how are you using .MouseButton1Click in a server script, you cant do that

Try looking at some Tutorials, DevForum or even MorphMagic FreeModels.

Actually MorphMagic FreeModels would help more since tutorials in youtube are outdated and is like 10 min long for ad revenue.

2 Likes

Would you mind sending me some to look at? I am only finding one in the toolbox.

i think youre best bet is to have a physical button with a billboard gui on it, and a click detector inside the physical button

when the button is clicked

button.ClickDetector.MouseClick:connect(function(playerWhoClicked)

the argument “playerWhoClicked” is an instance of the player who clicked the button.

I found this one, it looks kinda bad the scripting but i think you can fix it to match yours.

local plr = game.Players.LocalPlayer
local part = workspace:WaitForChild("Part")
local button = part:WaitForChild("TextButton")

button.MouseButton1Click:Connect(function()
	--do code
end)

If you have GuiObjects in the world space then you can reference them correctly from within the workspace directory inside of a local script placed inside the StarterPlayerScripts folder.