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

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

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)

2 comments

0

"Name" not "name"

0

its fine it works i tried it with print(name) it said CjayPlyz

2 answers

✓ Accepted answer

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)

1 comment

0

thanks, but i already figured out the answer.

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

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