Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago
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

Log in to vote
0
Answered by 9 years ago

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.

Ad

Answer this question