I’m experiencing a lag spike whenever I equip a tool in my game.
https://gyazo.com/6c8ea1e5b011ee49c003b9029a978ab2
I somewhat modified Roblox’s tool and I don’t use Welds. Instead, I use a Motor6D in torso. I use character.ChildAdded and check is it a Tool, if yes, I’ll process the child to this function:
function UpdateTool(newchar, Tool)
WeaponTool = Tool
Remotes.ConnectM6D:FireServer(Tool.BodyAttach)
coroutine.wrap(function()
WeaponToolStats = FindWeaponStats(Tool.Name)
offset = CFrame.new(WeaponToolStats.adsoffset_X,WeaponToolStats.adsoffset_Y, WeaponToolStats.adsoffset_Z)
Animations.Idle = hum:LoadAnimation(Tool.Animations.IdleAnim)
Animations.Idle2 = hum:LoadAnimation(Tool.Animations.Idle2Anim)
Animations.Equip = hum:LoadAnimation(Tool.Animations.EquipAnim)
Animations.Shoot = hum:LoadAnimation(Tool.Animations.ShootAnim)
Animations.Reload = hum:LoadAnimation(Tool.Animations.ReloadAnim)
UIP.MouseIconEnabled = false
Animations.Idle:Play()
Animations.Equip:Play()
newchar.Torso.ToolGrip.Part1 = Tool.BodyAttach
WeaponToolStats.CurrentAccuracy = WeaponToolStats.BaseAccuracy
end)()
return
end
Is there any problem with this code causing such function? This is stored inside a client starter script.
WeaponToolStats
is an table with stats and FindWeaponStats
is a function that find out the corresponding stats in the table.
FindWeaponStats:
function FindWeaponStats(ToolString)
for i,v in pairs (Weapons) do
if v.WeaponName == ToolString then
return v
end
end
return
end