Jump to content

UpdateWorld Function error

Recommended Posts

I'm trying to create a script that spawns an object every so often at a set time, but I keep getting a script error that says " '=' expected near 'function'". I'm new to programming and have no clue what that means. here's a screenshot of it in context. ANy help would be very appreciated.


Script.spawnObject = "" --entity "Object"
Script.spawnTimer = 1.5 --float "Spawn timer"
function Script:UpdateWorld()
self.timer = self.timer + (Time:GetSpeed()/100)
if(self.timer > self.spawnTimer) then
 local newObject = self.spawnObject:Instance()
 self.timer = 0


Share this post

Link to post

In fact, you have never told to lua that Script.timer is a number and what is it's initial value. So, when your program reaches the line that says


self.timer = self.timer + (Time:GetSpeed()/100)


The value of the self.timer is nil. You cannot add nil to a number.


So, in order to fix this, you just have to say


Script.timer = 0


in the third line of your code. That way, Lua will know that your variable is a number and what is it's initial value.


EDIT In fact, it seems that your program never gets into the UpdateWorld function. That's because it expects you to put a = somewhere "near" the function. Anyway, initialize Script.time = 0, and you'll be fine.

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...