Jump to content

Train Lag


Recommended Posts

I made this script from scratch and it works fine for 10 or so seconds then starts to lag and crash the server.

function traingo() 
        setTrainSpeed(myTrain, -0.5) -- Speed up 
        setTrainSpeed(car1, -0.5) -- Speed up 
        setTrainSpeed(car2, -0.5) -- Speed up 
        setTrainSpeed(car3, -0.5) -- Speed up 
        setTrainSpeed(car4, -0.5) -- Speed up 
        local timer = setTimer (traingo, 1000, 0) 
end 
addCommandHandler("go",traingo) 

Whats wrong? (there is more to it but that part works fine)

I type /go and the train goes fine

I stand on the back and it works fine

10 secs later it lags heaps and i have to restart the server

Link to comment

It's seems like recursion. When you type cmd it's make 1 infinite timer. When this timer reached ( 1 sec ) this make next infinite timer and etc.

In your case you use not infinite timer. ( just 1 sec ).

pTimer = setTimer ( traingo, 1000, 1 ) 

Also i think you not needed use timer local because you need destroy.

Link to comment

That's odd cos I had it without a local before and I didn't work so I tried adding a local to fix it.o well I hav another problem with it now. When I get other people on it the individual carriages begin to break up. Gaps form in the train and some carriges disappear or lose their physical part so you fall throug the floor of them.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...