How to add Humanoid:UnequipTools() into this

I want to make it so where if you tase someone there tools will stay unequipped

don’t know where to put it and it’s doing it but it wont keep doing it, for example I tase someone and they have a tool out and it unequips but they can just re-equip

I’ve tried a while true do loop but it just broke the taser

event.OnServerEvent:Connect(function(plr, target)	
	if target.Parent:FindFirstChild("Humanoid") and Isfired == false and script.Parent.Ammo.Value == 1 then
		if (target.Position - plr.Character.HumanoidRootPart.Position).Magnitude <= 20 then
			local targetpl = game.Players:GetPlayerFromCharacter(target.Parent)
			
			Isfired = true
			script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1
			local Att1 = Instance.new("Attachment")
			Att1.Parent = target
			
			local Att2 = Instance.new("Attachment")
			Att2.Parent = target.Parent.Torso
			
			local Rope1 = Instance.new("Beam")
			Rope1.Parent = script.Parent.Cart
			Rope1.LightEmission = 0.4
			Rope1.Width0 = 0.02
			Rope1.Width1 = 0.02
			Rope1.Attachment0 = script.Parent.Cart.TaserRope1
			Rope1.Attachment1 = Att1
			Rope1.Name = "Rope1"
			
			local Rope2 = Instance.new("Beam")
			Rope2.Parent = script.Parent.Cart
			Rope2.LightEmission = 0.4
			Rope2.Width0 = 0.02
			Rope2.Width1 = 0.02
			Rope2.Attachment0 = script.Parent.Cart.TaserRope2
			Rope2.Attachment1 = Att2
			Rope2.Name = "Rope2"
			
			target.Parent.Humanoid:UnequipTools()
			target.Parent.Humanoid.PlatformStand = true
			script.Parent.Cart.Confetti.ConfettiOne.Enabled = true
			script.Parent.Cart.Confetti.ConfettiTwo.Enabled = true
			script.Parent.Cart.Confetti.ConfettiThree.Enabled = true
			script.Parent.Cart.Confetti.ConfettiFour.Enabled = true
			script.Parent.Handle.Sound1:Play()
			wait(0.5)
			script.Parent.Handle.Sound2:Play()
			
			wait(5)
			
			script.Parent.Cart.Confetti.ConfettiOne.Enabled = false
			script.Parent.Cart.Confetti.ConfettiTwo.Enabled = false
			script.Parent.Cart.Confetti.ConfettiThree.Enabled = false
			script.Parent.Cart.Confetti.ConfettiFour.Enabled = false
			
			local FindRope1 = script.Parent.Cart:FindFirstChild("Rope1")
			if FindRope1 then
				FindRope1:Destroy()
			end
			
			local FindRope2 = script.Parent.Cart:FindFirstChild("Rope2")
			if FindRope2 then
				FindRope2:Destroy()
			end
			target.Parent.Humanoid.PlatformStand = false
			Isfired = false
		end
	end
end)

If you’re using immediate SignalBehavior then you can add a connection to the player’s character that will do a deferred UnequipTools call if a child of the Tool class is added to the character. You can then disconnect it later when it’s no longer necessary to force their tools to be unequipped.

Crude example:

-- Make the connection first
local forceUnequipTools = targetCharacter.ChildAdded:Connect(function (newChild)
    if newChild:IsA("Tool") then
        task.defer(targetHumanoid.UnequipTools, targetHumanoid)
    end
end)

-- Disconnect it later
if forceUnequipTools.Connected then
    forceUnequipTools:Disconnect()
end
1 Like

thank you, but the problem is I can’t put it outside the actual event, target isn’t defined outside of it.

Who says you need to put it outside the event? You can create and disconnect another connection on the same lines as your other code creating the effects.

1 Like