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

Why won't the int value(wood) go into the player folder Inventory?

Asked by 4 years ago
Edited 4 years ago

Yes other dumb question but the int value (wood) won't go into the inventory

here's the script

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if(player.Inventory:FindFirstChild("Wood")) then
        player.Inventory:WaitForChild("Wood").Value = player.Inventory:WaitForChild("Wood").Value +1
    elseif (not player.Inventory:FindFirstChild("Wood")) then
        local wood = Instance.new("IntValue", player)
        wood.Name = "Wood"
        wood.Value = 1
    end
    script.Parent.Parent:Destroy()
end)

and there's no error in the output

1
You're parenting the IntValue to the player not the inventory. Narunzo 172 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

You set the wood's parent to the player, not the Backpack. Also, you're supposed to use "Backpack", not "Inventory." Try this:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if(player.Backpack:FindFirstChild("Wood")) then
        player.Backpack:WaitForChild("Wood").Value = player.Backpack:WaitForChild("Wood").Value +1
    elseif (not player.Backpack:FindFirstChild("Wood")) then
        local wood = Instance.new("IntValue")
        wood.Name = "Wood"
        wood.Value = 1
    wood.Parent = player.Backpack
    end
    script.Parent.Parent:Destroy()
end)
0
I'm making a inventory gui Eric_pokemon 133 — 4y
0
my bad for not saying that beforehand Eric_pokemon 133 — 4y
0
but this solution does work Eric_pokemon 133 — 4y
0
if you replace the backpack to Inventory Eric_pokemon 133 — 4y
Ad

Answer this question