How To Save Player's Walk Speed When They Die?

I want it so that when a player dies, we should save their walk speed. And when he spawns again, we should apply the saved walk speed of the player.

I have this local script (I will explain later):

script.Parent.MouseButton1Click:Connect(function()
	
	local Player = game.Players.LocalPlayer
	local Open = script.Parent.Open
	
	if Open.Value == false then
		Open.Value = true
			script.Parent.Text = "2X Speed: On"
			script.Parent.BackgroundTransparency = 0
			Player.Character.Humanoid.WalkSpeed = 25
			

	elseif Open.Value == true then
		Open.Value = false
			script.Parent.Text = "2X Speed: Off"
			script.Parent.BackgroundTransparency = .5
			Player.Character.Humanoid.WalkSpeed = 16
			
	end
	
end)

Inside a text button, there is the above local script and a ‘BoolValue’ called ‘Open’.

Whenever a player dies, their walkspeed will be set to 16, (which is the default walk speed).

Now in my game, the player’s will continuously die, because my game is an obby. And people continuously die from lazers etc. So the players won’t like it when they will have to again and again press the textbutton every time they die just to increase their speed. Because they will die so many times.

So is there anyway to just save their walk speed when they die. And set it to the saved value?

I don’t need datastores:

I just want to save their walkspeed when they die, not when they leave the game.

Thanks for any help.

Maybey in a local script make a humanoid.died event and in the event save the players walkspeed in a variable then make another event called player.characterAdded and set the walkspeed to the variable you just set before.

The humanoid should still be in the character when they die, so on a death event you can save their walkspeed ads a variable then on a player.CharacterAdded:Wait() then reset the humanoids walkspeed to the variable from earlier.

1 Like

So this is what I did in the same local script:

local Player = game.Players.LocalPlayer
local Open = script.Parent.Open

local walkSpeedBeforeDeath
Player.Character:WaitForChild("Humanoid").Died:Connect(function()
	print("Died!")
	walkSpeedBeforeDeath = Player.Character.Humanoid.WalkSpeed
end)

Player.CharacterAdded:Connect(function()
	print("Inside CharacterAdded Event!")
	Player.Character:WaitForChild("Humanoid").WalkSpeed = walkSpeedBeforeDeath
end)

script.Parent.MouseButton1Click:Connect(function()
	
	if Open.Value == false then
		Open.Value = true
			script.Parent.Text = "2X Speed: On"
			script.Parent.BackgroundTransparency = 0
			Player.Character.Humanoid.WalkSpeed = 25
			

	elseif Open.Value == true then
		Open.Value = false
			script.Parent.Text = "2X Speed: Off"
			script.Parent.BackgroundTransparency = .5
			Player.Character.Humanoid.WalkSpeed = 16
			
	end
	
end)

And now the walk speed is being saved.

[quote=“Soban06, post:5, topic:839479, full:true”]
So this is what I did in the same local script:

local Player = game.Players.LocalPlayer
local Open = script.Parent.Open

local walkSpeedBeforeDeath
Player.Character:WaitForChild("Humanoid").Died:Connect(function()
	print("Died!")
	walkSpeedBeforeDeath = Player.Character.Humanoid.WalkSpeed
end)

Player.CharacterAdded:Connect(function()
	print("Inside CharacterAdded Event!")
	Player.Character:WaitForChild("Humanoid").WalkSpeed = walkSpeedBeforeDeath
end)

script.Parent.MouseButton1Click:Connect(function()
	
	if Open.Value == false then
		Open.Value = true
			script.Parent.Text = "2X Speed: On"
			script.Parent.BackgroundTransparency = 0
			Player.Character.Humanoid.WalkSpeed = 25
			

	elseif Open.Value == true then
		Open.Value = false
			script.Parent.Text = "2X Speed: Off"
			script.Parent.BackgroundTransparency = .5
			Player.Character.Humanoid.WalkSpeed = 16
			
	end
	
end)

And now the walk speed is being saved.

Please correct my script if I am using some bad practises.

3 Likes

You are doing this locally it might create some problems later on

1 Like

I honestly feel like that using data stores are better

Can the problems be serious? Can you tell what the problems can be?

Can be replication problem like for client he will run according to walkspeed but for others he will be of default speed

I suggest make a remote for change speed and handle it that way.