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

Why does this script stop working after I die and respawn?

X = 3
W = -3
Q = Vector3.new(3,0,0)
E = Vector3.new(-3,0,0)


game:GetService("RunService"):BindToRenderStep("Walk", Enum.RenderPriority.First.Value, function()
local Input = game:GetService("UserInputService")
print("working")
if Input:IsKeyDown(Enum.KeyCode.W) then
game.Players.LocalPlayer.Character.Humanoid:MoveTo(game.Players.LocalPlayer.Character.Torso.Position + (game.Players.LocalPlayer.Character.Torso.CFrame.lookVector * X))
end
if Input:IsKeyDown(Enum.KeyCode.A) then
game.Players.LocalPlayer.Character.Humanoid:MoveTo(game.Players.LocalPlayer.Character.Torso.CFrame * E)
end
if Input:IsKeyDown(Enum.KeyCode.S) then
game.Players.LocalPlayer.Character.Humanoid:MoveTo(game.Players.LocalPlayer.Character.Torso.Position + (game.Players.LocalPlayer.Character.Torso.CFrame.lookVector * W))
end
if Input:IsKeyDown(Enum.KeyCode.D) then
game.Players.LocalPlayer.Character.Humanoid:MoveTo(game.Players.LocalPlayer.Character.Torso.CFrame * Q)
end
end)

game.Players.LocalPlayer.CharacterRemoving:connect(function()
	game:GetService("RunService"):UnbindFromRenderStep("Walk")
end)

The Title says it all.

1 answer

✓ Accepted answer

I don't know too much about BindToRenderStep, but I'm guessing you need to call it every time the player spawns, like so:

X = 3
W = -3
Q = Vector3.new(3,0,0)
E = Vector3.new(-3,0,0)

game.Players.LocalPlayer.CharacterAdded:connect(function()
	game:GetService("RunService"):BindToRenderStep("Walk", Enum.RenderPriority.First.Value, function()
		local Input = game:GetService("UserInputService")
		print("working")
		if Input:IsKeyDown(Enum.KeyCode.W) then					game.Players.LocalPlayer.Character.Humanoid:MoveTo(game.Players.LocalPlayer.Character.Torso.Position + (game.Players.LocalPlayer.Character.Torso.CFrame.lookVector * X))
		end
		if Input:IsKeyDown(Enum.KeyCode.A) then
				game.Players.LocalPlayer.Character.Humanoid:MoveTo(game.Players.LocalPlayer.Character.Torso.CFrame * E)
		end
		if Input:IsKeyDown(Enum.KeyCode.S) then
			game.Players.LocalPlayer.Character.Humanoid:MoveTo(game.Players.LocalPlayer.Character.Torso.Position + (game.Players.LocalPlayer.Character.Torso.CFrame.lookVector * W))
		end
		if Input:IsKeyDown(Enum.KeyCode.D) then
			game.Players.LocalPlayer.Character.Humanoid:MoveTo(game.Players.LocalPlayer.Character.Torso		.CFrame * Q)
		end
	end)
end)

game.Players.LocalPlayer.CharacterRemoving:connect(function()
    	game:GetService("RunService"):UnbindFromRenderStep("Walk")
end)

Also, you should really indent your code. I tried, but this editor isn't the best for it.

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