Trying to make a run script, but it couldn’t be a normal local script run script due to me needing to change the running/walking values. The script works fine but after the humanoid dies the scripts stop working.
Here is the local script:
local UIS = game:GetService("UserInputService")
local p = game.Players.LocalPlayer
local RS = script.Parent:WaitForChild("RunServer")
local CWV = RS:WaitForChild("CurrentWalkValue")
local CRV = RS:WaitForChild("CurrentRunValue")
UIS.InputBegan:Connect(function(key, IsTyping)
if IsTyping then return end
if key.KeyCode == Enum.KeyCode.LeftControl then
script.Parent.RunServer.Run:FireServer()
end
end)
CRV.Changed:Connect(function()
script.Parent.RunServer.CH:FireServer()
end)
CWV.Changed:Connect(function()
script.Parent.RunServer.CH:FireServer()
end)
The server script:
local c = script.Parent
local IsRunning = script:WaitForChild("IsRunning")
local CWV = script:WaitForChild("CurrentWalkValue")
local CRV = script:WaitForChild("CurrentRunValue")
local RE = script:WaitForChild("Run")
local GE = c:WaitForChild("GunEquipped")
local CH = script:WaitForChild("CH")
local DefaultCRV = 30
local DefaultCWV = 16
RE.OnServerEvent:Connect(function()
if IsRunning.Value == false then
if GE.IsAiming.Value ~= true then
c.Humanoid.WalkSpeed = CRV.Value
IsRunning.Value = true
end
elseif IsRunning.Value == true then
c.Humanoid.WalkSpeed = CWV.Value
IsRunning.Value = false
end
end)
IsRunning.Changed:Connect(function()
if IsRunning.Value == false then
c.Humanoid.WalkSpeed = CWV.Value
elseif IsRunning.Value == true then
c.Humanoid.WalkSpeed = CRV.Value
end
end)
GE.Changed:Connect(function()
if GE.Value == false then
CRV.Value = DefaultCRV
CWV.Value = DefaultCWV
end
end)
CH.OnServerEvent:Connect(function()
if IsRunning.Value == false then
c.Humanoid.WalkSpeed = CWV.Value
elseif IsRunning.Value == true then
c.Humanoid.WalkSpeed = CRV.Value
end
end)
Both are in starter character scripts
(If it helps, CurrentRunValue and CurrentWalkValue are ints, IsRunning is a bool.)