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

Where can I get the location for a player's "Humanoid" or their Health?

Asked by 4 years ago

Im trying to make a button that will kill the player that clicks it, this is what i've got:

script.Parent.MouseClick:Connect(function(click)
    click.Parent.Humanoid.Health = 0
end)

The problem is that no matter how many different ways i try to do the second line it always says that Humanoid isn't a a child, can someone tell me how to find it or another way I could do this?

3 answers

Log in to vote
0
Answered by
kepiblop 124
4 years ago
Edited 4 years ago

Thing is. You cant set a player health on a script you want to use a local script. If you still prefer a script then you wanna use :TakeDamage()

local db = false --using debounce cause takedamage can cause lag if used too much
script.Parent.MouseClick:Connect(function(click)
if db then return end
db = true
    local char = click.Character
    char.Humanoid:TakeDamage(100)
wait(5) --time until player spawns
db = false
end)

0
I didn't know this so thanks, ill def use it later mikechris333 10 — 4y
0
yw kepiblop 124 — 4y
Ad
Log in to vote
0
Answered by
A_Mp5 222 Moderation Voter
4 years ago

I'm not fully sure, but it may be that "click" is the Player in Game.Players, and not Game.Workspace, since Workspace is where Player's characters and humanoids are stored.

Log in to vote
0
Answered by
QWJKZXF 88
4 years ago

The reason your script isn't working is because you are getting the Player from game.Players, not the Character. It may seem a bit confusing, but when a person joins the game, Roblox splits your avatar into two things, a player(which is responsible for storing tools, GUIs, etc), and a character(which allows you to move around the world and do stuff).

When you clicked, what happens is that it returns the name of the player that clicked it, not the character.

In the script below, you get the character of the player, and set its health to 0.

script.Parent.MouseClick:Connect(function(click)
    local char = click.Character
    char.Humanoid.Health = 0
end)

0
This makes a lot more sense, thanks! mikechris333 10 — 4y

Answer this question