Error when trying to unequip tools

So I am making a script so that when a player is holding a weapon and they sit down in a car their weapon will be unequipped. I made a local script and put it inside of one of my tools.

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

script.Parent.Equipped:Connect(function()
	if humanoid.Sit == true then
		humanoid:UnequipTools()
	end
end)

The issue I am having is that when a player is already sitting down and they equip a weapon I get this error “Something unexpectedly tried to set the parent of AK-47 to Backpack while trying to set the parent of AK-47. Current parent is emrek” emrek is my username and the AK-47 is the weapon.

I tested this, you need to add a wait()

might i also suggest a

humanoid.Seated:Connect(function()
	wait()
	humanoid:UnequipTools()
end)

to unequip the AK when you sit in the seat?

1 Like