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:

01--drgigabyte
02local debounce = false
03 
04script.Parent.Touched:Connect(function(hit)
05    if not debounce then
06        debounce = true
07        local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
08        if plr then
09            plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 10
10            local holders = {plr:FindFirstChild("Backpack"), plr:FindFirstChild("StarterGear"), hit.Parent}
11            for i,v in pairs(holders) do
12                pcall(function()
13                    for i,v in pairs(v:GetChildren()) do
14                        if v:IsA("BackpackItem") then
15                            v:Destroy()
View all 23 lines...

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:

1if plr then
2            plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 10
3            local holders = {plr:FindFirstChild("Backpack"), plr:FindFirstChild("StarterGear"), hit.Parent}
4            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