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

Can someone explain to me why the humanoid speed is not being changed?

I've made this script that changes the players speed to the value in the leaderboards name called "speed" and I am trying to make sure that when their speed on the leaderboard is 0 then it would automatically put it to 16 until it goes above 16 however it only seems to stay at 16 the entire time

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        local humanoid = char:WaitForChild("Humanoid")
		humanoid.WalkSpeed = player.leaderstats.speed.Value
		if player.leaderstats.speed.Value <= 16 then
			humanoid.WalkSpeed = 16 
		end
		 
    end)
end)

If you can explain to me what I've done wrong please do.

p.s I am new to scripting

1 answer

✓ Accepted answer

Well what you're doing is almost right! But if we break down what's going on

if player.leaderstats.speed.Value <= 16 then

It is indeed checking if the value is 0 or anything less than 16, and if so it makes it 16. But what you're not doing is, if the speed value is higher than 16, you're not also setting it! You're missing the else part

if player.leaderstats.speed.Value <= 16 then
	humanoid.WalkSpeed = 16
else
	humanoid.WalkSpeed = player.leaderstats.speed.Value
end

What we are saying here is: whenever the leaderstats speed is less than 16, turn it to 16, if it's anything that's less than 16 turn it to what the leaderstats speed value is

2 comments

0

Thanks!

0

No problem!

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