Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
MemezyDev 172
4 years ago
Edited 4 years ago

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!

0
instead of doing "if not yes then" have you tried doing "if yes == false then"? Ieowyyn 69 — 4y
0
if not checks if the value is false, if checks if its true MemezyDev 172 — 4y
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 Magicdevice3 58 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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

Ad

Answer this question