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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
starmaq 1290 Moderation Voter
4 years ago
Edited 4 years ago

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

0
Thanks! Everbyte 6 — 4y
0
No problem! starmaq 1290 — 4y
Ad

Answer this question