Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why do this script freeze my game / increase my ping by a lot ?

Asked by 2 years ago
Edited 2 years ago

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)

0
This doesn't look harmful or have any loops that could crash your Studio. Is there anything else? Xapelize 2658 — 2y
0
I think this was because of the script having too much work to do. As you see, every 0.2 seconds, the script will delete the value, create the value, delete the value, create the value for 3 - 5 seconds cool_u10u 0 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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.

Ad

Answer this question