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

Script should change walkspeed according to the hiddenstats but not working? [SOLVED]

Asked by
CjayPlyz 643 Moderation Voter
6 years ago
Edited 6 years ago

I have a shop where if you buy +1 JumpPower get +1 JumpPower, i made so it saves too, i made this script so that if you join back after leaving the game you get the powerups back

game.Players.PlayerAdded:connect(function(player)

    local speed = player.hiddenstats.AddedJump.Value
    local name = player.name
    local character = workspace[player].Humanoid.JumpPower 
    character = speed + 50

end)
0
"Name" not "name" greatneil80 2647 — 6y
0
its fine it works i tried it with print(name) it said CjayPlyz CjayPlyz 643 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

The main problem with your script is that Humanoid is never found. The event is fired off when a player joins and it doesn't wait for the character model to spawn.

With the CharacterAdded event you'll be sure the character model is spawned.

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local speed = 222 --player.hiddenstats.AddedJump.Value
        local humanoid = character:FindFirstChild("Humanoid")

        humanoid.JumpPower = speed + 50
    end)
end)
0
thanks, but i already figured out the answer. CjayPlyz 643 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Line 1, line 4 and line 5.

In line 1, you should say :Connect since :connect is deprecated. Deprecated code can cause problems, such as lag, and delay. When something is deprecated, Roblox internally do something to the deprecated item, making it either not work or lag/delay your code.

In line 4, you just didn't add the uppercase N, unless there was an actual object called "name".

In line 5, you said workspace[player] when you just add the .Name so:

game.Workspace[player.Name]

The PlayerAdded event passes the player ****object**** as a parameter, not the name of the player

And when you assigned it the Humanoid's JumpPower, you assigned it the JumpPower's current value. Not for the property itself. The default humanoid jumping power is 50, so it was like assigning:

local character = 50

Answer this question