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

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

Asked by 6 years ago
Edited 6 years ago

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)"

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. PreciseLogic 271 — 6y
0
This has been answered, please mark it as answered. Thank you. User#21242 20 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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!

Ad

Answer this question