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

Why won't the players get killed at the end of the timer?

Asked by
CodeWon 181
3 years ago
Edited 3 years ago

I was creating a timer for an obby game and I wanted it to kill you when it gets to 0. The timer worked fine, but the kill didn't.

Note: I don't know much about scripting so don't come at me if this script is super messed up.

if secondsvalue.Value <= 0 then
    game.Players:GetChildren("Humanoid")
    game.Players.Humanoid.Health = 0
else
    warn("Error")
end
0
I hope my answer doesn't sound too snappy! :) COOLGUY16T 37 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

First of all GetChildren() Doesn't have any parameters so nothing should be inside the brackets. If you want the script to find something with a specific name, use FindFirstChild() and put the name inside the brackets. Second of all, you are trying to make the Player List's Humanoid Health to 0. The player list doesnt have a humanoid, let alone any health. To kill all the players, you must loop through all the players, get their character and set their humanoid health to 0. Third of all, you are not identifying the secondsvalue correctly. For example, if the seconds value was inside the script, you would do:

if script.secondsvalue.Value == 0 then

and if it was inside the workspace you would do:

if game.Workspace.secondsvalue.Value == 0 then

Here is your script but modified so it will work(make sure that secondsvalue is a number value and for this script you won't need to warn but keep using it as it is a good habit to get in to)

while wait() do --waits a millisecond before checking if the seconds value is equal to zero.
    if script.secondsvalue.Value== 0 then

for _,v in pairs(game.Players:GetChildren()) do --This "loops through" the children of "Players"
    v.Character.Humanoid.Health = 0--Gets the players humanoid and sets its health to 0
    end
end
end

Good luck on your journey through Roblox Lua! :)

Ad

Answer this question