theonlysnowflake Posted August 26, 2015 Share Posted August 26, 2015 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" Script.timer function Script:UpdateWorld() self.timer = self.timer + (Time:GetSpeed()/100) if(self.timer > self.spawnTimer) then local newObject = self.spawnObject:Instance() newObject:SetPosition(self.entity:GetPosition()) self.timer = 0 end end Quote Link to comment Share on other sites More sharing options...
Lunarovich Posted August 26, 2015 Share Posted August 26, 2015 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. 1 Quote Link to comment Share on other sites More sharing options...
theonlysnowflake Posted August 28, 2015 Author Share Posted August 28, 2015 Oh my gosh I totally knew that. Oops. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.