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

:Equip() glitching for first equip but works after that, and Unequip() won't work?

Asked by
Vid_eo 126
4 years ago

I'm making a custom inventory GUI.

For whatever reason whenever a gun gets equipped for the first time it's really glitchy, but then when it gets equipped again it's fine. I waited for all the assets to load in the gun first too & use :WaitForChild in both the script below and the gun's scripts. There are no errors in output.

The gun also doesn't unequip.

Script:

equipped = false

game.ReplicatedStorage.Events.EquipUnequipEvent.OnServerEvent:Connect(function(plr, equippedVal, humanoid, scriptActivateImg, equippedImage, unequippedImage)
    if equippedVal.Value ~= "" then
        if equipped == false then 
            local Tools = game.ReplicatedStorage:WaitForChild("Tools")
            humanoid:EquipTool(Tools[equippedVal.Value]) --glitching here?
            print("equipped")
            equipped = true
        elseif equipped == true then
            humanoid:UnequipTools() --glitching here?
            print("unequipped")
            equipped = false
        end
    end
end)

Thanks!

Answer this question