4
votes

Hello I am writing a scipt on ROBLOX and I have encountered a problem.

function showVictoryMessage(playerName)
    local message = Instance.new("Message")
    message.Text = playerName .." has won!"
    message.Parent = game.Workspace
    wait (2)
    message.Destroy()
end

Upon running this function, or more specifically the "message.Destroy" command, I get the error: Error in script: '=' expected near '< eof >'

I have never seen this error before, and the ROBLOX wiki page on Lua errors doesn't mention it.

I would very much appreciate help in this, because I don't personally know anyone who has coded in Lua.

3
no further hints, like line number? - Marcus Müller
I'm not a Lua pro, but I think the .. on the third line looks suspiciously like a syntax error. - elixenide
Nope. But It doesn't matter much because I only call that command once in the whole script, and running the individual comman "message.Destroy" gets the exact same error. So it has something to do with that particular command. - Wingless Wallaby
Ed It is not. The .. is replaced with the player name which is determined by some earlier code. Also when the message appears on the screen .. is filled in by the player's name just fine. It is only the deleting of the message that isn't working. - Wingless Wallaby
.. is the concat operator. It isn't "replaced" by anything. That's what the playerName variable is. - Etan Reisner

3 Answers

4
votes

Looks like a syntax error. message.Destroy() should be message:Destroy() according to this Roblox wiki page http://wiki.roblox.com/index.php?title=API:Class/Instance/Destroy

Also see the section Explosions, Messages, and More at URL http://wiki.roblox.com/index.php?title=Basic_Scripting which provides similar syntax using the colon (:) operator.

See also Difference between . and : in Lua and explanation of "possible side-effects of calculations/access are calculated only once" with colon notation.

2
votes

Instead of message.Destroy() it should be message:Destroy()

Remember that '.' are used directory-wise and ":' are used for inbuilt functions.

1
votes

WOOOOOOOO! It was a syntax error. The correct command is message:Destroy. Cause why would object.Destroy work and message.Destroy not?