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

Is "then" appropriate?

Asked by 10 years ago

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

Log in to vote
2
Answered by 10 years ago

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)
Ad
Log in to vote
0
Answered by
bbissell 346 Moderation Voter
10 years ago

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

Answer this question