Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My scripts not working?

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

✓ Accepted answer

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)

3 comments

0

Ditto is there a way so every 5 seconds it does 20 damage? @Diito

0

Yes. Hold on, let me edit my answer.

0

Done. Sorry for the wait.

This discussion is preserved as it was. New answers, comments, and votes are closed.