Expected identifier when parsing expression, got 'then'

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? why my script isnt working

  2. What is the issue? It says Expected identifier when parsing expression, got ‘then’

  3. What solutions have you tried so far? all the solutions are from 2013 and didn’t really help much

1 Like

theres no if, thats why it errored.

(theres a then, and an else)


tool.Value = if return.Value.Inventory.OwnedTools[tool.name] then returnValue.Inventory.OwnedTools[tool.Name] else false
1 Like

Ternary conditions syntax is if cond then exp else exp as stated above.

1 Like

Small mistake in your code:

should actually be

returnValue.Inventory.OwnedTools[tool.Name] ~= nil then

Also, here’s another way to do the same thing:

tool.Value = (returnValue.Inventory.OwnedTools[tool.Name] ~= nil and returnValue.Inventory.OwnedTools[tool.Name] or false)


return.Value.Inventory.OwnedTools[tool.name] is the same thing, it just doesn’t have the ~= nil,


means it is checking if exsisting, you can go test this in studio

this is like saying if 3 then end, 3 is a thing

edit: oh, i just saw da error, i thought you were talking about the if not having a ~= nil, super sorry :sob:

1 Like

I’m aware that ~= nil isn’t needed at all.

From what I can see, you’re doing return.Value.Inventory.OwnedTools[tool.name] when it should actually be returnValue.Inventory.OwnedTools[tool.Name].

If I am wrong I apologise. You are right with what I mentioned above though.

Note: You just found it. No worries :rofl:

Edit: You should be able to make the code even shorter by doing this:

tool.Value = (returnValue.Inventory.OwnedTools[tool.Name] or false)
1 Like

thanks for the fix

sorry for my super defensive attitude

edit after yours: yeah that is a nice little fix

1 Like

No problem man. I’m new to posting so I’m trying not to get anything wrong.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.