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

i am making a simulator game but the walk speeds do not match up....?

i am making a simulator game and in it as you grow on size your walk speed gets slower so i tried this at first

game.Players.PlayerAdded:Connect(function(player)

        local humanoid = player.Humanoid
      
         humaoid.WalkSpeed = 16 * (Weight.Value / 250)
        
end)

but when you are at 0 weight(its my leaderstats) you do not move at all and even if you get to 16 to 17 weight your walk speed is not at all proportionate so then i tried this

game.Players.PlayerAdded:Connect(function(player)

        local humanoid = player.Humanoid
      
         humaoid.WalkSpeed = 16 * (Weight.Value + 1 / 250)
        
end)

but this made player go too fast now please tell me what i am doing wrong their are no errors in my script

2 answers

✓ Accepted answer

I have a few answers, try them and see which one fits your preference:

#1. Nguyenlegiahung's answer (improved)

game:GetService("Players").PlayerAdded:Connect(function(plr) 
-- When a Player is Added
	plr.CharacterAdded:connect(function(char) 
-- When a player's character is added
		local hum = char:WaitForChild("Humanoid")
 -- Get the player's humanoid
		pcall(function() 
-- Basically a function that stops errors from stopping the whole script
			local loopc1 = coroutine.wrap(function() 
-- Basically a silent function
				while wait() do
 -- Forever loop
					hum.WalkSpeed = 16 * (Weight.Value / 250) + 1 
-- The equation
				end
			end) loopc1() -- Run the silent function
		end)
	end)
end)

#2. Making sure WalkSpeed isn't 0

game:GetService("Players").PlayerAdded:Connect(function(plr) 
-- When a Player is Added
	plr.CharacterAdded:connect(function(char) 
-- When a player's character is added
		local hum = char:WaitForChild("Humanoid")
 -- Get the player's humanoid
		pcall(function() 
-- Basically a function that stops errors from stopping the whole script
			local loopc1 = coroutine.wrap(function() 
-- Basically a silent function
				while wait() do
 -- Forever loop
					hum.WalkSpeed = (16 * 1) * (Weight.Value / 250)
-- The equation
				end
			end) loopc1() -- Run the silent function
		end)
	end)
end)

#3. Answer #1 and #2 combined

game:GetService("Players").PlayerAdded:Connect(function(plr) 
-- When a Player is Added
	plr.CharacterAdded:connect(function(char) 
-- When a player's character is added
		local hum = char:WaitForChild("Humanoid")
 -- Get the player's humanoid
		pcall(function() 
-- Basically a function that stops errors from stopping the whole script
			local loopc1 = coroutine.wrap(function() 
-- Basically a silent function
				while wait() do
 -- Forever loop
					hum.WalkSpeed = ((16 * 1) * ((Weight.Value / 250) + 1))
-- The equation
				end
			end) loopc1() -- Run the silent function
		end)
	end)
end)

1 comment

0

Nice response!

I suggest you put +1 outside the bracket

game.Players.PlayerAdded:Connect(function(player)

        local humanoid = player.Humanoid

         humaoid.WalkSpeed = 16 * (Weight.Value / 250) +1 -- If it too fast then you can change it to +.5

end)

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