local function Running(speed) if speed > 0.1 and CanSlide then if…
- User
local function Running(speed) if speed > 0.1 and CanSlide then if Character.Values.Locked.Value == false then TweenService:Create(Camera, TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {FieldOfView = CameraSettings.FOV.Value - 10}):Play() end for _, leg in {"Left Leg", "Right Leg"} do local legObj = Character[leg] if legObj then local SprintParticle = legObj:FindFirstChild("Sprint") if SprintParticle then SprintParticle.Enabled = true end end end else if Character.Values.Locked.Value == false then if not sprinting then TweenService:Create(Camera, TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {FieldOfView = CameraSettings.FOV.Value}):Play() end end for _, leg in {"Left Leg", "Right Leg"} do local legObj = Character[leg] if legObj then local SprintParticle = legObj:FindFirstChild("Sprint") if SprintParticle then SprintParticle.Enabled = false end end end end end
there is identical code. fix this.
- Assistant
You can refactor the code by creating a separate function to handle enabling/disabling the Sprint particle for each leg. Here is the updated code with the refactored function:
local function SetSprintParticleEnabled(legObj, isEnabled) local SprintParticle = legObj:FindFirstChild("Sprint") if SprintParticle then SprintParticle.Enabled = isEnabled end end local function Running(speed) if speed > 0.1 and CanSlide then if Character.Values.Locked.Value == false then TweenService:Create(Camera, TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {FieldOfView = CameraSettings.FOV.Value - 10}):Play() end for _, leg in ipairs({"Left Leg", "Right Leg"}) do local legObj = Character[leg] if legObj then SetSprintParticleEnabled(legObj, true) end end else if Character.Values.Locked.Value == false then if not sprinting then TweenService:Create(Camera, TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {FieldOfView = CameraSettings.FOV.Value}):Play() end end for _, leg in ipairs({"Left Leg", "Right Leg"}) do local legObj = Character[leg] if legObj then SetSprintParticleEnabled(legObj, false) end end end end - User
there is still two fors..
- Assistant
You can combine the two for loops into one by checking the condition inside the loop. Here is the updated code with a single for loop:
local function SetSprintParticleEnabled(legObj, isEnabled) local SprintParticle = legObj:FindFirstChild("Sprint") if SprintParticle then SprintParticle.Enabled = isEnabled end end local function Running(speed) local fieldOfViewChange = 0 if speed > 0.1 and CanSlide then if Character.Values.Locked.Value == false then fieldOfViewChange = -10 end else if Character.Values.Locked.Value == false and not sprinting then fieldOfViewChange = 0 end end TweenService:Create(Camera, TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {FieldOfView = CameraSettings.FOV.Value + fieldOfViewChange}):Play() for _, leg in ipairs({"Left Leg", "Right Leg"}) do local legObj = Character[leg] if legObj then SetSprintParticleEnabled(legObj, speed > 0.1 and CanSlide) end end endIn this code, we have combined the two for loops into one by checking the condition inside the loop and setting the parameter accordingly when calling the function.