Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is "then" appropriate?

I am new to scripting. So forgive me for my mistake.

So I get the error

19:26:12.544 - Workspace.Script:4: 'then' expected near '='

when running this script

am = Workspace.AmmoCrate1.AmmoCrate

while true do
	if am.Amount.Value = 0
    wait(30)
    am.Amount.Value = am.Amount.Value + 1000

end

I'm trying to make it that if The AmmoCrate's Value hits 0, then it will wait for 30 seconds until its Value returns to 1000.

2 answers

Well first, instead of using a while loop for this just use the Changed event

	am.Changed:connect(function()

	end)

Secondly an if statement should be used like this

if condition then
--code
end

You forgot both the then and the end.

And third when comparing two values you have to use == instead of just =

So it would be:

if value == 5 then

end

instead of

if value = 5 then

end

So if you put this altogehter the code would look like this

local am = Workspace.AmmoCrate1.AmmoCrate

am.Changed:connect(function() --use the changed event
	if am.Value == 0 then --if the value is 0
		am.Value = 1000 --change the value to 1000
	end --end the block of code
end)

You need two equal signs when using an if statement and then you need to follow it by a then. Thats why its called an if then statement

    if am.Amount.Value == 0 then

This discussion is preserved as it was. New answers, comments, and votes are closed.