-
What do you want to achieve? I’m making a script that make the player move right if he hold R
-
What is the issue? The script stop working if player die
-
What solutions have you tried so far? I tried to look at the script and see if there is any issue but I don’t notice any thing and I tried to disable the script and enable it again if player die but its still stop working when player die
This is the script (Its a local script and its in StarterPlayerScripts)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local humanoid = Character:WaitForChild("Humanoid")
local Moving = false
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
UserInputService.InputBegan:Connect(function(keyCode, Chatted)
if Chatted then
return
end
local HRP = Character:FindFirstChild("HumanoidRootPart")
if HRP ~= nil and keyCode.KeyCode == Enum.KeyCode.R then
Moving = true
while Moving do
humanoid:Move(Vector3.new(2,0,2))
RunService.RenderStepped:Wait()
end
end
end)
UserInputService.InputEnded:Connect(function(keyCode)
local HRP = Character:FindFirstChild("HumanoidRootPart")
if HRP ~= nil and keyCode.KeyCode == Enum.KeyCode.R then
Moving = false
Character:MoveTo(HRP.Position)
end
end)