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

Why when I die, the walkspeed does not save?

So I made a script saying if you have one coin, walkspeed is = 21

	local players = game.Players.LocalPlayer
	 
	script.Parent.MouseButton1Click:Connect(function(Click)
	    if players.leaderstats.Coins.Value >= 1 then
	        players.leaderstats.Coins.Value = players.leaderstats.Coins.Value - 1
	 
	        players.Character.Humanoid.WalkSpeed = 21
	    end
	end)

But it came to my attention that when you die, your walkspeed get reset. can you help me? (Keep in mind that I have more than one of these scripts, and each one costs more and makes you faster.)

4 comments

0

Or, you could just disable the reset button

0

that's not what he wanted

0

Why are you changing the WalkSpeed on the client? Do it on the server.

0

So what are you saying? Sorry, I am sorta new to scripting.

2 answers

✓ Accepted answer

You could save the value of the walkspeed somewhere other than the script and have another script load the walkspeed. You could also go to extremes and use datastores to save their data even when they leave the game (Save the walkspeed value in the player, not the character).

Btw, even with the new improvements, this script wouldn't work because player.Character doesn't work in localscripts. Or, if this isn't a localscript, Game.Players.LocalPlayer only works in localscripts. I Hope this helps!

1 comment

0

So what are you saying? Sorry, I am sorta new to scripting.



game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAddded:Connect(function(character)
		script.Parent.MouseButton1Click:Connect(function()
			if player.leaderstats.Coins.Value >= 1 then
				player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1
				walkspeedbeforedeath = 21
				character.Humanoid.WalkSpeed = walkspeed
			end
		end)
	end)
end)

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:WaitForChild("Humanoid"):Connect(function(character)
		character.Humanoid.WalkSpeed = walkspeedbeforedeath
	end)
end)

again, idk if this works, but it's pretty much what I can help. If it doesn't work, please be more specific as you can and try searching it on google.

11 comments

1

I don't like when people just paste scripts and expect OP to figure it out. Add comments at the very least.

0

This would work. I'll explain it to you as best as I can. Line 1: Detectign when a player joins the game and defining the player that joined as "player"

0

Line 2: Detecting when the player's character is created and loaded. Defines the character as "character"

0

Line 3: Detecting when the script's parent is clicked.

0

Line 4: Does this player have enough coins?

0

Line 5: If it does, reduce the coin count by 1.

0

Line 6: Saving the walkspeed in the script.

0

Line 7:Giving the character the correct amount of walkspeed.

0

Line 7 would fail as "walkspeed" isn't defined. Say "walkspeedbeforedeath" instead.

0

I also don't think you would need the last 5 lines. Just replace line 2 with line 15 and it should work.

0

Also line 2 has an extra d.

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