Hey, I’m kinda tired right now so I have no idea what i’m doing. Trying to get our games released by march so I’m trying to get all these useless bugs fixed if anyone can help me fix my running script not play after running once that would be cool. Video + Script below.
LocalScript:
local Services = {
Players = game:GetService("Players"),
RunService = game:GetService("RunService"),
RS = game:GetService("ReplicatedStorage"),
TS = game:GetService('TweenService'),
CAS = game:GetService('ContextActionService')
}
local Player = Services.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera
local Remote = Services.RS:WaitForChild("Event")
local animTrack = nil
local canSprint = true
local isSprinting = false
local sprintAnim = Instance.new("Animation")
sprintAnim.AnimationId = "rbxassetid://" .. 8755953869
local FOVIn = Services.TS:Create(
Camera,
TweenInfo.new(.5),
{FieldOfView = 71}
)
local FOVOut = Services.TS:Create(
Camera,
TweenInfo.new(.5),
{FieldOfView = 70}
)
local function handleSprintAction(actionName, inputState, inputObject)
if actionName == "Sprint" and inputState == Enum.UserInputState.Begin and canSprint and Humanoid.MoveDirection.Magnitude > 0.01 then
isSprinting = true
animTrack = Humanoid:LoadAnimation(sprintAnim)
animTrack:Play()
Humanoid.WalkSpeed = 20.5
elseif actionName == "Sprint" and inputState == Enum.UserInputState.End and canSprint then
if animTrack ~= nil then
animTrack:Stop()
animTrack = nil
end
Humanoid.WalkSpeed = 16
isSprinting = false
end
end
Services.CAS:BindAction("Sprint", handleSprintAction, true, Enum.KeyCode.LeftShift)
Services.CAS:SetTitle("Sprint", "Sprint")
Services.CAS:SetPosition("Sprint",UDim2.new(1, -70, 0, 10))
Services.RunService.RenderStepped:Connect(function()
if isSprinting then
FOVIn:Play()
else
FOVOut:Play()
if not animTrack == nil then
animTrack = Humanoid:LoadAnimation(sprintAnim)
animTrack:Play()
isSprinting = false
end
end
end)
Remote.OnClientEvent:Connect(function(val)
if val == "CantMove" then
Services.CAS:UnbindAction("sprint")
canSprint = false
if animTrack ~= nil then
animTrack:Stop()
animTrack = nil
end
elseif val == "CanMove" then
Services.CAS:BindAction("Sprint", handleSprintAction, true, Enum.KeyCode.LeftShift)
Services.CAS:SetTitle("Sprint", "Sprint")
Services.CAS:SetPosition("Sprint",UDim2.new(1, -70, 0, 10))
canSprint = true
end
end)
Video: