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

Why does this script not kill the player?

Asked by
DogeIXX 172
5 years ago

Hey, I did not ask a question for a longer time. (I guess thats good tho)

Problem

I am trying to make a script that kills a player after some time if they do not touch a part.

Script

for i, user in ipairs(game.Players:GetChildren()) do
    local char = user.Character
    local part = workspace.InZone
    local h = part.Parent:FindFirstChild("Humanoid")
    if h~= nil then
        h.Health = h.Health -200
    end
end

3 answers

Log in to vote
0
Answered by
asadefa 55
5 years ago

I seriously don't see why you bother with this workspace.InZone thing. Also is this a script or localscript? (It should be a script)

for i, user in ipairs(game.Players:GetChildren()) do local char = user.Character char:FindFirstChild("Humanoid") if h~= nil then h.Health = h.Health -200 end end

Ad
Log in to vote
0
Answered by
poke7667 142
5 years ago
Edited 5 years ago

In order to do this, you must make a loop to count time and a checker for when the part has been touched. There are 2 functions that do this, :GetTouchingParts() Or the event, Touched. Here are wiki articles for them: Touched GetTouchingParts

If you have anymore questions reply to this answer.

Log in to vote
0
Answered by 5 years ago

Try This:

for i, user in ipairs(game.Players:GetChildren()) do
    local char = user.Character
    local humanoid = char.Humanoid
    humanoid.Health = humanoid.Health - 100
end

Make sure it is a Script not a LocalScript.

Hope this helps!

Answer this question