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

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

Asked by 2 years ago
Edited 2 years 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:https://www.youtube.com/watch?v=eiyDXlQg5tI

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): https://drive.google.com/file/d/1z_PiygqxRHXkTd1xNftERz8XqDJiYsKu/view?usp=sharing

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

        Item.MouseButton1Click:Connect(function()

            local ValueToChange = Inventory:FindFirstChild(Item.Name)

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

local PlaceEvent = game.ReplicatedStorage.PlaceEvent

PlaceEvent.OnServerEvent:Connect(function(PreviewObject)

    local ValueToChange = Player.Inventory:FindFirstChild(PreviewObject)

    if ValueToChange.Value - 1 >= 0 then
        ValueToChange.Value -=5
    print("Value was decreased")
    end
end)
0
What’s ValueToChange.Value - 1 for? Puppynniko 1059 — 2y

Answer this question