So, I was making a damage script for my game. When you attack, it creates an StringValue called "Attacking", then the touched event connects, while you have this stringvalue, you will attack the opponent. But for some reason, I was creating a barrage move. When I test it on a Dummy, the attack froze the game (in roblox studio), increase ping by ALOT (in Roblox player, can increase ping to over 25k ms. This is a server script, whenever a tool wants to damage, It will fire this script. It also gives no errors or anything.
local event = game.ReplicatedStorage.Damage local stunhit = false local hitt = 0 event.OnServerEvent:Connect(function(player, partdmg, dmg, attacktime, cd, soundid, soundvolume) if cd == 0 then return end local chr = player.Character if cmd == "normalattack" then local candamage = Instance.new("StringValue") candamage.Name = "Attacking" candamage.Parent = chr candamage.Value = "NotHit" game.Debris:AddItem(candamage, attacktime) partdmg.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and chr:FindFirstChild("Attacking").Value == "NotHit" then if hitt == 1 then return end hitt = 1 hit.Parent.Humanoid:TakeDamage(dmg) candamage.Value = "IsHit" local sound = Instance.new("Sound") sound.Volume = soundvolume sound.Name = "hitsound" sound.MinDistance = 1 sound.MaxDistance = 20 sound.SoundId = soundid sound.Parent = hit.Parent.Torso sound:Play() game.Debris:AddItem(sound, 5) wait(cd) hitt = 0 end return end) end end)
I managed to reduce the lag and freeze. So the problem was is that the script has to loop create the value and delete the value for 3-5 seconds. This work is too much for the server / script to handle, so I managed to reduce the work (by a lot). So now, the script will only create 1 value. And delete it when the move is over.