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

How do I get this movement Script (or LocalScript I'm not sure) to work properly?

Hello, I found this piece of code off the internet for a test project. It is supposed to make your character gradually gain speed when it moves. However, I keep getting the error "Humanoid is not a valid member of Player" Here is the script in question:

chr = game.Players.LocalPlayer hum = chr.Humanoid inrate = 0.2 -- how fast it increases decayrate = 0 -- how fast it decreases inamount = 1 -- how much it increases deamount = 0.5 -- how much it decreases max = 16 -- the max speed speed = 0 -- no need to change this spawn(function()

while wait(decayrate) do
	if speed > 0 and hum.MoveDirection == Vector3.new(0,0,0) then
		speed = speed - deamount
		hum.WalkSpeed = hum.WalkSpeed - deamount
	end
end

end) while wait() do while hum.MoveDirection ~= Vector3.new(0,0,0) and (speed+inamount) < max do wait(inrate) speed = speed + inamount hum.WalkSpeed = hum.WalkSpeed + inamount

end

end

Could somebody please tell me what is wrong and how I can fix it? Any help is appreciated.

1 comment

0

Well first of all, where is the script at, Because there are no humanoids that control the physical character in game.Players, and that script is sketchy

1 answer

local player = game.Players.LocalPlayer
local chr = player.Character or player.CharacterAdded:Wait()
local hum = chr:WaitForChild("Humanoid")

also if you are doing game.Players.LocalPlayer, then it must be LocalScript

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