#item not destroying if Angry = 1

2 messages · Page 1 of 1 (latest)

plain reef
#

local object = script.Parent
local itemsValue = game.workspace.items 
local moneyFolder = game.ReplicatedStorage:FindFirstChild("Money")


local function debugPrint(...)
    print("[ItemScript]", ...)
end


local function spawnMoney()
    if moneyFolder and #moneyFolder:GetChildren() > 0 then
        local randomMoney = moneyFolder:GetChildren()[math.random(1, #moneyFolder:GetChildren())]:Clone()
        randomMoney.Parent = game.Workspace
        debugPrint("Money spawned")
    end
end


local function handleGasCard()
    debugPrint("Gas card conditions check:", 
        "GasCardPicked =", game.Workspace.GasCardPicked.Value,
        "items =", itemsValue.Value,
        "GasCardDestroyed =", game.Workspace:FindFirstChild("GasCardDestroyed") and game.Workspace.GasCardDestroyed.Value or "nil")


    if game.Workspace.GasCardPicked.Value == 1 then
        repeat wait(0.1) until itemsValue.Value == 2
        debugPrint("All gas card conditions met, destroying object...")
        object:Destroy()


        wait(0.1)
        game.Workspace.GasCardPicked.Value -= 1
        game.Workspace.GasCard.Value -= 1

        spawnMoney()
        return true 
    end
    return false 
end


local function handleRegularItem()
    if itemsValue.Value == 1 then
        debugPrint("Regular item condition met, destroying object...")
        object:Destroy()
        spawnMoney()
        return true 
    end
    return false 
end

#

continuation of script