The gun is ran by 1 local script and 1 server script using FastCast in ServerStorage. My question is how by commenting does it make lag go down? I feel as though that would not fix anything.
Situation update:
I replaced all the Wait()s with “task.wait()” and deleted a dummy that lags when u kill it from the game and ive brought down the memory a bit and its freed up like 100+ MB
I have noticed that some people use a semi colon after a line for example
end;
-- or even,
end);
i was wondering if that means anything and if it affects the script in anyway?
You may want to check microprofiler for the reason of the huge latency between frames, it can help you identify whether it may be a physics issue ,or identify the group of scripts causing the issue.
Doesn’t seem like much code to cause performance issues.
While, ofc task.wait() is superior to wait(), I don’t think it will cause such a noticeable performance drop.
That’s optional in luau, and it has no impact on performance.
It might be the fast cast module the gun script relies on to work.
FastCast is a well tested module, so I don’t think the issue comes from there. You could open up micro profiler as such:
I dont know how to use the micro profiler. How do you use it? What is it even for?
You could read this article
Is this in studio? Try using it in game too, and lowering your graphics quality.
Ive tested the gun with microprofiler and it appears to have these large orange bars mostly when equiping and unequipping the gun
The runJob is what appears to have the most calls
However i found the guns Local script and it seems to be getting called 29 times when equipping.
Im not sure if this means anything or what runJob even does
Can you show the code which equips/unequips the gun?
Yeah, i recently added some checkers to stop a idle animation bug
Equip Script:
firearm.Equipped:Connect(function()
IdleAnim:Stop()
Mouse.Icon = MouseIcon
Equipped = true
if character.Humanoid then
IdleAnim:Stop()
task.wait(.05)
EquipAnim:Play()
task.wait(0.9)
EquipAnim:Stop()
if Equipped == true then
Idling = true
IdleAnim.Looped = true
IdleAnim:Play()
else
Idling = false
Equipped = false
IdleAnim:Stop()
end
if Jammed == true then
game.Players.LocalPlayer.PlayerGui.GunHUD.MAG.ThisGunJammedBro.Visible = true
else
end
else
warn("No humanoid?")
end
end)
Unequip script:
firearm.Unequipped:Connect(function()
Mouse.Icon = ""
if IdleAnim then
IdleAnim:Stop()
UnequipAnim:Play()
Idling = false
Equipped = false
end
end)
Honestly, I don’t see any issue with the scripts
Mabye it could be runJob? I saw that get called the most
Useful tips for debugging when you have no clue what causes issues:
- use print statements to identify what code is ran
- Progressively disable more and more (comment out) until the issue is resolved
The second point is probably the best for your usecase. You already found out it’s when someone does, or shoots. You should start from those functions and keep disabling more and more features until the issue is fixed.
So i decided to delete everything in my game, and my memory still ran at 1.8KMB in studio when everything apart from baseplate is deleted
Try optimizing the code that triggers when a bullet hits a player.
But how can i optimise this?? Ive already used task.wait() since it’s more reliable
Removing bloaty functions caching some things maybe. Hard to say without having the code to pinpoint the problem.
Memory doesn’t mean much. Especially memory in studio.
You should only investigate memory if your players experience crashes in game
Going from assumptions is useless, as memory is dependent on the device. If the device supports it, Roblox will use more memory.
Are you actually having performance issues? Or are you just going off the assumption of “memory is too high”?