Humanoid WalkSpeed resets if you reset character

Hello, im developing a speed simulator game and struggling on this bug. So, basically:

  1. I have a leaderstats value which sets Players walkspeed in server script.
  2. When I try to reset my character, walkspeed goes back to default and player cant increase speed anymore.
Players.PlayerAdded:Connect(function(Player)
	
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local Humanoid = Character:WaitForChild('Humanoid')
	
	local isMoving = false
	
	local FreakinessAmount = 0.01
	
	Humanoid.WalkSpeed = 0 -- Starting speed
	
	Humanoid.Changed:Connect(function(Property)
		
		if Property == "MoveDirection" then
			
			if Humanoid.MoveDirection == Vector3.zero then
				isMoving = false
			else
				isMoving = true
			end
			
		end
		
	end)
	
	local Leaderstats = Player:WaitForChild('leaderstats')
	local Freakiness = Leaderstats.Freakiness
	
	repeat
		
		if isMoving then
			Freakiness.Value += (FreakinessAmount * FreakinessMultiplier)
			Humanoid.WalkSpeed = Freakiness.Value
		end
		
		wait(.1)
		
	until false
	
	Player.Character:WaitForChild('Humanoid').Died:Connect(function()
		SpeedBeforeDeath = Humanoid.WalkSpeed
	end)
	
	Player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").WalkSpeed = SpeedBeforeDeath
	end)
	
end)	

**Also this warning fiers if i reset: ** RunService:UnbindFromRenderStep removed different functions with same reference name utility-focus-state-inspect-abkolia228 2 times.

1 Like

It seems that the problem is that when you reset the character, the WalkSpeed ​​is reset to the default value.

Players.PlayerAdded:Connect(function(Player)

local Character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Character:WaitForChild(‘Humanoid’)

local isMoving = false

local SpeedBeforeDeath = Humanoid.WalkSpeed ​​-- Variable to store speed before death

local FreakinessAmount = 0.01

local FreakinessMultiplier = 1 – Assumption: FreakinessMultiplier is defined or globally available

Humanoid.WalkSpeed ​​= 0 – Starting speed

Humanoid.Changed:Connect(function(Property)

if Property == “MoveDirection” then

if Humanoid.MoveDirection == Vector3.new(0, 0, 0) then

isMoving = false

else
isMoving = true

end
end
end)

local Leaderstats = Player:WaitForChild(‘leaderstats’)

local Freakiness = Leaderstats.Freakiness

local function increaseFreakiness()

while isMoving do

Freakiness.Value = Freakiness.Value + (FreakinessAmount * FreakinessMultiplier)

Humanoid.WalkSpeed ​​= Freakiness.Value

wait(0.1)

end

end

spawn(increaseFreakiness) – spawn function for an asynchronous loop

Player.Character:WaitForChild(‘Humanoid’).Died:Connect(function()

SpeedBeforeDeath = Humanoid.WalkSpeed

end)

Player.CharacterAdded:Connect(function(character)

character:WaitForChild(“Humanoid”).WalkSpeed ​​= SpeedBeforeDeath

end)

end)

( I correct scripts myself and let AI check again to see if it really works, please don’t take offense :disappointed_relieved:)

1 Like

Does IT Work or give IT Errorcodes :smiley:?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.