How to disable tool equip for some time

Hello, :wave:

I am currently working on player stunning system (for my taser), where if players get stunned then they won’t be able to equip any tools…
For this to happen I have tried using Humanoid:UnequipTools() inside a while loop (while loop so as to not equip it continuously).

Here is what I tried out…

local disableTools = coroutine.create(function()
    while stunned do
       humanoid:UnequipTools()
       wait()
   end
end)

-- When stunned
coroutine.resume(disableTools)

-- When stunning is over
coroutine.yield(disableTools)

But the issue is that, whenever we try to equip the tool after getting stunned, it gets equipped for a few milliseconds after which the scripts forces to unequip it…

So I am trying to avoid this delay between equipping and unequipping…(which i have not idea how to do)

Thanks a lot for helping in advance!

5 Likes

Just unequip their tool and disable the CoreGui for backpack

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
15 Likes

Try listening to Character.ChildAdded as a loop instead and if the child is a Tool, do unequipTools.

local disableTools = character.ChildAdded:Connect(function(child)
    if child:IsA(“Tool”) then
       humanoid:UnequipTools()
    end
end)

local function enableTools()
    disableTools:Disconnect()
end

The above reply works but client is untrusted and could probably pull some tricks anyways even if the tool core is invisible, maybe they could turn it back visible?

To be honest, you should just remove the tools and grant them back once they are able to use it again.

3 Likes

why do i have this sent what rip