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

I'm trying to make it so a brick clears your inventory and gives you money?

Asked by 7 years ago

This is what I have:

--drgigabyte
local debounce = false

script.Parent.Touched:Connect(function(hit)
    if not debounce then
        debounce = true
        local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if plr then
            plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 10
            local holders = {plr:FindFirstChild("Backpack"), plr:FindFirstChild("StarterGear"), hit.Parent}
            for i,v in pairs(holders) do
                pcall(function()
                    for i,v in pairs(v:GetChildren()) do
                        if v:IsA("BackpackItem") then
                            v:Destroy()
                        end
                    end
                end)
            end
        end
        debounce = false
    end
end)

However every time someone steps on the brick it gives you money even if you don't have any tools.

1 answer

Log in to vote
-1
Answered by 7 years ago

Im Not sure how to exactly re-script to show you the problem, but if see in this part of the code:


if plr then plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 10 local holders = {plr:FindFirstChild("Backpack"), plr:FindFirstChild("StarterGear"), hit.Parent} for i,v in pairs(holders) do

Your giving the money before you are checking if the tool/Item is in their backpack.

Ad

Answer this question