Problem with door-system

Hey there, im currently working on a Keycard system for one of my games.

Now i encountered this problem while remaking it.
Screenshot_76

I atually dont know what to do right there. I tried removing this “end”, adding more etc. But as soon as i did that, the last “end” got marked.

3 Likes

you need an end at line 99 and looks like you need 2 more at the end

2 Likes

Add a end after the else if. and one after the other if statment. Make sure all if statments have one end. Dont add a end efter a if statment if you’re gonna add a else if.

1 Like

When creating an if and elseif statement, you have to ensure that you finish each statement off with and “end.” Unlike elseif, when you create another if within it, it counts as a separate statement and you are required to close off this separate statement with an end.

4 Likes

By the way, ‘eof’ means ‘end of file’.
So what that error message is saying is that it expected ‘end’ to close an ‘if then’ statement starting at line 92, but instead it got to the end of the file.

6 Likes

Thanks for that information! I actually didnt knew that.

Aside from the fact you were missing end’s after each if 14 == true then block you are also comparing truthy values to true, which means that code will run every time, making those conditions unnecessary.

This is incorrect, however this is how it works in some languages such as JS which has an === operator that works the same way as in lua. Comparing truthy values to true only results in true if the value is actually true itself. However, doing if x then will always run if x is truthy (Not nil, not false).

-- Will run
if true == true then
    print("true == true")
end
-- Will not run
if "abc" == true then
    print("abc == true")
end
-- Will run
if "abc" then
    print("abc")
end
-- Will not run
if nil then
    print("nil")
end
-- Still will not run
if false then
    print("false")
end

My mistake. In that case none of his code blocks will run at all. I don’t think his script is going to work even with the syntax corrections the other people suggested here.

I think l4 and l5 may be to keep track of which doors are enabled. For example, Flauschi might set l4 to false so the fourth door would not open, and l5 to true so the fifth door can open.

It looks like you’re repeating yourself there a lot too. You could reduce this by simply using or in your if statements; e.g.

local hitName = hit.Parent.Name
if ((hitName == "Keycard4" and l4) or (hitName == "Keycard5" and l5)) then
    tween1open:Play()
    tween2open:Play()
    tween2open.Completed:Wait() -- This will wait for "tween2open" to finish before continuing
    tween1close:Play()
    tween2close:Play()
end

I see it now. For some reason I was under the impression he was using plain numbers in those boolean conditions.

1 Like