I have a script that is causing the client memory usage to spike and i cant figure out why.
–Heres The Script
game.ReplicatedStorage.PlayerFire.RemoteEvent.OnServerEvent:Connect(function (player, hum, value)
if hum then
hum.WalkSpeed = value
end
if hum then
for _, track in pairs(hum:GetPlayingAnimationTracks()) do
if track.Name == "SMG_RELOAD" then return end
end
local animator = hum:FindFirstChild("Animator")
local animTrack = animator:LoadAnimation(game.ReplicatedStorage.Animations.Running)
local animTrack2 = animator:LoadAnimation(game.ReplicatedStorage.Animations.WeaponRun)
local C = coroutine.create(function ()
while task.wait(0.1) do
if hum then
-- Check for "crouch" animation and stop it if playing
if hum.WalkSpeed == 10 then
animTrack:Stop()
animTrack2:Stop()
elseif hum.WalkSpeed > 16 and not hum.Sit and not hum.Parent:FindFirstChild("Tool") and hum.MoveDirection.Magnitude > 0 then
for _, track in ipairs(animator:GetPlayingAnimationTracks()) do
if track.Name == "Crouch" then
game.ReplicatedStorage.PlayerFire.CrouchSprint:FireClient(player)
track:Stop()
end
end
if not animTrack.IsPlaying then
animTrack2:Stop()
animTrack:Play()
animTrack:AdjustSpeed(2)
end
elseif hum.WalkSpeed > 16 and not hum.Sit and hum.Parent:FindFirstChild("Tool") and hum.MoveDirection.Magnitude > 0 then
for _, track in ipairs(animator:GetPlayingAnimationTracks()) do
if track.Name == "Crouch" then
track:Stop()
end
hum.Parent:FindFirstChild("Tool").Unequipped:Connect(function ()
return
end)
end
if not animTrack2.IsPlaying then
animTrack:Stop()
animTrack2:Play()
animTrack2:AdjustSpeed(2)
end
else
animTrack:Stop()
animTrack2:Stop()
end
end
end
end)
coroutine.resume(C)
end
end)