Log in to vote

Why does this Int value decide to not subtract, and instead do the complete opposite??

Asked by 18 days ago
Edited 18 days ago

I'm currently building an inventory/shop/buildable system, the inventory system relies on int values in a folder of the actual player to tell how many items each player has. A player can buy an item from the "shop" (on the right) then click on the item in there inventory GUI and place it. When a player buys an item it causes the int value in the players inventory folder to increase, when they place this item, it fires a Remote event which triggers the placement of the item and is supposed to trigger a subtraction of the int value. Instead it does the complete opposite, resetting the value to 1 and then increasing from there. Below are a couple screenshots and a video along with the code in question. Anyone have ideas on why this is happening and how to fix it?

Example of the problem:

Image of explorer (In yellow is the remote function I mentioned, In green are the int values in question and in blue is the GUI for the inventory, everything else is named and pretty self explanatory):

Code that makes the Int values go up and down:

local Player = game.Players.LocalPlayer
local Inventory = Player:WaitForChild("Inventory")
local Frame = script.Parent

for i, Item in pairs(Frame:GetChildren()) do

    if Item:IsA("TextButton") then


            local ValueToChange = Inventory:FindFirstChild(Item.Name)

            ValueToChange.Value = ValueToChange.Value +1
            print("value was increased")

local PlaceEvent = game.ReplicatedStorage.PlaceEvent


    local ValueToChange = Player.Inventory:FindFirstChild(PreviewObject)

    if ValueToChange.Value - 1 >= 0 then
        ValueToChange.Value -=5
    print("Value was decreased")
What’s ValueToChange.Value - 1 for? Puppynniko 419 — 17d

Answer this question