Its supposed to say PLAYER died when you press it. It works fine when its just "Died" Is there something wrong.
I have already tried p = hit.Character
and label.Text = p.. "Died!"
local label = script.Parent.SurfaceGui.TextLabel function Onclick(hit) label.Text = hit.Character.. "Died!" wait(.1) hit.Character.Head:remove() end script.Parent.ClickDetector.MouseClick:connect(Onclick)
The MouseClick
event returns the player that clicked. So when you index Character
and try to concatenate it with a string it's going to throw an error like;
Attempt to concatenate a userdata
This happens because the Character itself is a userdata. You need to index the Name
property - a string(:
local label = script.Parent.SurfaceGui.TextLabel function Onclick(hit) local char = hit.Character --Define the character here label.Text = char.Name.. "Died!" --Index 'Name' wait(.1) char.Head:Destroy() --'remove' is deprecated, use Destroy! end script.Parent.ClickDetector.MouseClick:connect(Onclick)
Problem: You never asked for the players name, just their physical character. Solution:
i = Instance.new("ClickDetector") i.Parent = script.Parent local label = script.Parent.SurfaceGui.TextLabel function Onclick(hit) label.Text = hit.Character.Name.. "Died!" wait(.1) hit.Character.Head:Destroy() -- remove is deprecated end script.Parent.ClickDetector.MouseClick:connect(Onclick)