Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I get :Destroy() to delete the tool while equipping it?

I am making a tool that is raw beef and I was gonna make it so after a certain amount of bites, the tool gets destroyed. I am destroying on the server, and I did connect with remotes. The tool does get destroyed, but after I unequip the tool

--Client
wait()
local yes = false
local tool = script.Parent
local bites = 0
local foodHandler = game:GetService('ReplicatedStorage'):WaitForChild('foodHandler')
local foodItem = tool.Name

tool.Activated:Connect(function()
	if not yes then
		yes = true
		eatAnim:Play()
		bites = bites + 1
		print(bites)
		wait(3)
		if bites == 3 then
			foodHandler:FireServer(foodItem) 
		end
		yes = false
	end
end)

--Server

local foodHandler = game:GetService('ReplicatedStorage'):WaitForChild('foodHandler')

local function removeFood(player, foodItem)
	player.Backpack:WaitForChild(foodItem):Destroy()
end
foodHandler.OnServerEvent:Connect(removeFood)

everything else in the script works. If you can help me then tysm!

3 comments

0

instead of doing "if not yes then" have you tried doing "if yes == false then"?

0

if not checks if the value is false, if checks if its true

0

I think I have an Idea Maybe do I a IF Statement to Get the amount of Bites and After It reaches The Amount You Want Move the Tool To Server Storage

1 answer

✓ Accepted answer

if possible use the Humanoid:UnequipTools() function so that it automatically unequips for you

This discussion is preserved as it was. New answers, comments, and votes are closed.