Unequipping tool loophole

I’m trying to make a system where if the value in my script is true it basically unequips the players tool, however, I’ve found a loophole where players can easily just spam equip and unequip the tool and they will have it even if the value is true. I’ve tried using while loops, but it didn’t seem to help either. Any help would be much appreciated. Thanks!

local player = script.Parent

local function isRagdolled()
	local ragdolledValue = player:FindFirstChild("Ragdolled")
	return ragdolledValue and ragdolledValue.Value == true
end

local function hasToolsEquipped()
	local tools = player:GetChildren()
	for _, tool in ipairs(tools) do
		if tool:IsA("Tool") then
			return true
		end
	end
	return false
end

local function unequipTool()
	if isRagdolled() then
		if hasToolsEquipped() then
			player.Humanoid:UnequipTools()
		end
	end
end

player:WaitForChild("Ragdolled").Changed:Connect(unequipTool)
unequipTool()

2 Likes

Try adding a debounce

Preformatted textlocal db = false
local player = script.Parent

local function isRagdolled()
local ragdolledValue = player:FindFirstChild(“Ragdolled”)
return ragdolledValue and ragdolledValue.Value == true
end

local function hasToolsEquipped()
local tools = player:GetChildren()
for _, tool in ipairs(tools) do
if tool:IsA(“Tool”) then
return true
end
end
return false
end

local function unequipTool()
if isRagdolled() then
if hasToolsEquipped() then
player.Humanoid:UnequipTools()
end
end
end

if db == false then
db = true
player:WaitForChild(“Ragdolled”).Changed:Connect(unequipTool)
wait(0.5)
db = false
end
Ignore me im just trying some things…

2 Likes

My bad for any confusion, the player can sometimes still have the tool equipped if they spam unequip and equip the tool. I’m trying to avoid the players tool to be equipped at all while the value is true.

Maybe u could try using the disabling the enabled property on the tool:


local function isRagdolled()
	local ragdolledValue = player:FindFirstChild("Ragdolled")
	return ragdolledValue and ragdolledValue.Value == true
local Tools = player:GetChildren()
for _, tool in Tools do
If tool:IsA("Tool") then
tool.Enabled = false
end

local function hasToolsEquipped()
	local tools = player:GetChildren()
	for _, tool in ipairs(tools) do
		if tool:IsA("Tool") then
			return true
		end
	end
	return false
end

local function unequipTool()
	if isRagdolled() then
		if hasToolsEquipped() then
			player.Humanoid:UnequipTools()
		end
	end
end

player:WaitForChild("Ragdolled").Changed:Connect(unequipTool)```
1 Like

Thank you so much. This works pretty good!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.