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

My scripts not working?

Asked by
duckyo01 120
9 years ago

I made a script so that if a players walk speed is at a certain speed they lose health each second heres what I have that does not work.

local Player = game.Players.LocalPlayer
if Player.Character.Humanoid.WalkSpeed >= 200 then
    Player.Character.Humanoid.Health = 85
    if Player.Character.Humanoid.WalkSpeed >= 300 then
        Player.Character.Humanoid.Health = 65
    end
end

This is in my starterpack as a local script.

1 answer

Log in to vote
1
Answered by
Diitto 230 Moderation Voter
9 years ago

You need to put the check in a loop, and subtract from their health constantly. Also, be consistent and be wary of errors.

local Player=Game:service'Players'.localPlayer;
local RunService=Game:service'RunService';

local HighDamage=5;--// If they are at a certain height
local MaxedDamage=10;
local HighSpeed=200;
local MaxedSpeed=300;

Spawn(function()--// Spawns a new co-routine.
    while(true)do
        local Humanoid=Player.Character and Player.Character:findFirstChild'Humanoid';
        if(Humanoid and Humanoid:isA'Humanoid')then --// Checks if the humanoid exists,
        --// and is actually a humanoid. (prevents errors from name collision)
            local Speed=Humanoid.WalkSpeed;
            local DamageTaken=Speed >= HighSpeed and (
                 Speed < MaxedSpeed and HighDamage or MaxedDamage 
            ) or 0;--// Aligns damage with speed.
            Humanoid:TakeDamage( DamageTaken );--// No harm in doing it if it's 0.
        end;
        wait(5);
    end;
end)

0
Ditto is there a way so every 5 seconds it does 20 damage? @Diito duckyo01 120 — 9y
0
Yes. Hold on, let me edit my answer. Diitto 230 — 9y
0
Done. Sorry for the wait. Diitto 230 — 9y
Ad

Answer this question