Okay so I am making stock for a vending machine but the script isn’t working.
local stock = game.Workspace.stockValue --Number Value
local stockValue = stock.Value
local stockHandler = stock.stockHandler.Value --Bool Value
stockValue = 100
while true do
if stockValue >= 0 then
print("Full")
else
print("Empty")
end
-- There is a script for the vending machine, if the player took something, the boolvalue is true, once the player already received the drink, the boolvalue is false.
if stockHandler then
stockValue -= 1
end
end
With the wait, I believe it doesn’t matter; it just has to be there. I also think you should try doing "if stockHandler.Value = " (putting whatever value you want it to be in the blank space). I’d also check to make sure the stockvalue itself is being set to 100, because I’ve found that trying to make a variable for a property and then setting a value with that property messes up.
Oh, I see the new issue. When checking if something equals something, you need to do == instead of =.
= is for setting something, == is for checking basically
you are setting variables to the values instead of setting the .Value of the number values
this is a rework of your code with comments read them so you can learn and compare it to your script above
local stock = game.Workspace.stockValue -- you access this in if statments by checking stock.Value
--local stockValue = stock.Value -- no need for this line this is just setting stockValue to the current it won't update it if it changes
local stockHandler = stock.stockHandler -- you don't need .Value here its referenced below in your if statment
stock.Value = 100 -- this actually sets the value to 100 before you were just setting stockValue varaible to 100
while wait() do -- you can just use your wait here since you want it to keep looping
if stock.Value >= 0 then -- check it like this by checking the actual .Value
print('Full')
else
print('Empty')
end
if stockHandler.Value then -- this is checking if Value exist and set true
stock.Value -= 1
end
end