#This script lags my game for 1 sec

1 messages · Page 1 of 1 (latest)

sleek breach
#

meatswordEvent.OnServerEvent:Connect(function(plr)
    plr.Character.Humanoid:UnequipTools()
    RemoveCurrentTool(plr)
    wait(0.1)
    local meatsword = game.ReplicatedStorage.WEAPONS.Meatsword
    meatsword:Clone().Parent = plr.Backpack
    
end)

axeEvent.OnServerEvent:Connect(function(plr)
    plr.Character.Humanoid:UnequipTools()
    RemoveCurrentTool(plr)
    wait(0.1)
    local axe = game.ReplicatedStorage.WEAPONS.Axe
    axe:Clone().Parent = plr.Backpack

end)
voltEvent.OnServerEvent:Connect(function(plr)
    plr.Character.Humanoid:UnequipTools()
    RemoveCurrentTool(plr)
    wait(0.1)
    local volt = game.ReplicatedStorage.WEAPONS.Voltsword
    volt:Clone().Parent = plr.Backpack

end)

function RemoveCurrentTool(plr)
    
    local character = plr.Character

    for _, tool in pairs(plr.Backpack:GetChildren()) do
        if tool:IsA("Tool") then
            tool:Destroy()
        end
    end
    if character then
        for _, tool in pairs(character:GetChildren()) do
            if tool:IsA("Tool") then
                tool:Destroy()
            end
        end
    end
end
#

Also if anyone has a better way of removing person's current inventory and giving a new weapon , pls giv tips.