What is wrong with this script?

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

1 Like

pretty sure you’ve gotta put a wait after the while true do. at least, that’s what i’ve noticed

Should I just do a normal “wait()” or make it wait a certain amount?

Edit: It does not help.

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.

The output

Workspace.stockScript:15: Expected 'then' when parsing if statement, got '='

Did you put the value you’re trying to check for?
edit: showing the script again would be simpler

The script I have now:

local stock = game.Workspace.stockValue
local stockValue = stock.Value
local stockHandler = stock.stockHandler.Value

stockValue = 100

while true do
wait()
if stockValue >= 0 then
print(“Full”)
else
print(“Empty”)
end

if stockHandler.Value = true then
	stockValue -= 1
end

end

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

1 Like

or change it to this which is just checking if its true also

I just noticed, the part where it says stockValue = 100, it doesn’t change it to 100.

Yeah, I probably should’ve pointed the out earlier

basically , never try to make a variable for a property and then set something using that variable

1 Like

Do you know why it doesn’t work?

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
1 Like

still not working, I have been trying for awhile now. I will try restarting the code and plan it out. will update when done.

1 Like

are you getting any print from this at all or error?

no, just that the code to decrease the stock is not working

are you setting that value somewhere to true

1 Like

I have been trying, nothing works. I decided I will not add this feature anymore. Thanks to everyone who tried to help.