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

How would I get the character from clicking a screengui?

TextButton = script.Parent.TextButton


TextButton.MouseButton1Up:Connect(function(click)
	print(click)-- Should print a weird number
end)

Whenever I click this gui text button unlike click detectors it keeps printing out a weird random number instead of a player that clicked it if i wanted to destroy the head of somone that clicked the gui how would I first get the character from this number that is being printed

1 answer

✓ Accepted answer

The reason for a number being printed is because the arguments passed to your callback function are the X and Y 2D coordinates of your mouse!

So in reality click was the X coordinate of your mouse!

You should just use the Players.LocalPlayer property to get the local player.

local TextButton = script.Parent.TextButton -- # use local variables
local client = game:GetService("Players").LocalPlayer -- # the player


TextButton.MouseButton1Up:Connect(function(x, y)
    print(x, y) -- # just so you see the X and Y coordinates
    client.Character.Head:Destroy()
end)

2 comments

0

oh is that a thing

0

I never new that existed

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