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

How do I make it so when a brick is touched an item is removed from the inv?

I'm trying to make it so a player can grab a box and bring it to a destination.. (I'm a noob to scripting) I would like to add "1" to a NumberValue when a box is delivered (I'd also like to remove the Box from the inventory after touch) this is what I have:

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
			local holders = {plr:FindFirstChild("Backpack"), plr:FindFirstChild("StarterGear"), hit.Parent}
			game.Workspace.itemStocks.numberofSoap = game.Workspace.itemStocks.numberofSoap + 1
			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
		wait(60)
		debounce = false
	end
end)

However I get an error in the output saying "20:47:44.955 - Workspace.End.Script:10: attempt to perform arithmetic on field 'numberofSoap' (a userdata value)"

2 comments

0

numberofSoap is a NumberValue, not a number value. NumberValues and all things you'd see in the Explorer are objects and cannot be added with another number (This is like adding "Apple" with 100, doesn't make sense right?). You need to get numberofSoap's value and add 1 onto it.

0

This has been answered, please mark it as answered. Thank you.

1 answer

You need to add ".Value" so, it will look like this:

game.Workspace.itemStocks.numberofSoap.Value = game.Workspace.itemStocks.numberofSoap.Value + 1

Paste this into line 9. Have fun scripting!

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