Recently, I have been making a runner game and one of the things I want to accomplish is to have the WalkSpeed remain in the same value whenever a Player dies based on the event Humanoid.Died:
I took a look on the forum to see if I could find any related topics, but I couldn’t find any that were related to my goal, leading me to create this post!
I remembered trying to make the WalkSpeed the same by using Humanoid.HealthChanged but that did not work either… I suppose I should try using an IntValue/NumberValue that keeps stored in the Player character and always puts WalkSpeed = IntValue?
Let me know if you know how I can solve this puzzle!
I suggest checking when the player dies, setting their walkspeed to a value, waiting for them to respawn, and then setting their speed to the old value after their character has loaded.
There is also a property under StarterPlayer that is a starting walkspeed.
Did what you said as I completely forgot about this factor, but it doesn’t seem to print or change after pressing Play on Roblox Studio neither if I die, rather than just stating that the user has died
You should probably use script.Parent instead of StarterPlayer.StarterPlayerScripts.
It tries to call the players character before it loads, to fix that I suggest putting
Player.CharacterAdded:Wait()
local Character = Player.Character
It never changes the character nor the humanoid to the new one when the player dies. Put this in the function that runs when the player’s character is added
Character = Player.Character
Humanoid = Character:WaitForChild("Humanoid")
Hello, here’s a simpler script that works (Parent it under StarterPlayerScripts):
local StarterPlayer = game:GetService("StarterPlayer")
local player = game.Players.LocalPlayer
local walkSpeed = StarterPlayer.CharacterWalkSpeed
local function onCharacterAdded(character: Model)
local humanoid : Humanoid = character:WaitForChild("Humanoid")
humanoid.WalkSpeed = walkSpeed
humanoid.Died:Once(function()
walkSpeed = humanoid.WalkSpeed
end)
end
player.CharacterAdded:Connect(onCharacterAdded)
That’s the same script as the one I mentioned earlier right? It saves the player’s previous speed and sets it to their new character. It looks like you didnt change the speed.
If you want to make the player start with a certain speed change the property in studio as I first mentioned.