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

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

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

✓ Accepted answer

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.

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