Hi! I have a train system that works really well. When it spawns in the 3rd time, it gets really bizarre. After it spawns in the 4th time, all the scripts in the train system don’t work.
Here are some screenshots of the train being bizarre:
Train=script.Parent
while true do
wait()
for i= 1, 50 do
Train:TranslateBy(Vector3.new(0.5, 0, 0))
wait()
end
end
Train regen script:
model = game.Workspace.Train
backup = model:clone()
while true do
wait(300)
model:remove()
model = backup:clone()
model.Parent = game.Workspace
model:makeJoints()
end
If you know a fix, please let me know. Thanks, WE.
I tried that, but it still does the same thing. What happens is the train spawns in as 2 trains the second time, and 3 trains the 3rd time, and 4 trains the 4th time and so on.
Why are you looping through something 50 times without doing something special afterward when you are already infinitely looping?
Are these GUIs Billboard Guis or Guis in the PlayerGui scripted using WorldToScreenPoint? It could possibly be an offset because of using :makeJoints(), could you possibly do that before you parent to the workspace? (If possible, using WeldConstraints will be better, as SurfaceType based joining is deprecated.) More info here
It would be nice to explain what exactly is breaking, (such as guis not being positioned correctly, the train going too fast, parts not being welded, etc) instead of showing some screenshots with lines. Also, Clone() should be capitalized.
The thing that doesnt work is the train robbery when the train duplicates like this. The train duplicates a lot and sometimes lags the game for slower devices.
You can see that the train is duplicated. The train is anchored because it falls out of the map. The move script is how it moves. I already know how to change it if the train is going too fast.
The way to fix it is to find out how to make a better move script and/or the regen.
Your current code will have the backup model get garbage collected, (removed from memory) so it’s likely erroring.
Try this code:
model = game.ServerStorage.Train -- change the current trains parent to ServerStorage
while true do
wait()
workspace.Trains.Train:Destroy() -- Make a new folder for trains in studio
local Clone = Train:Clone()
Clone.Parent = workspace
coroutine.resume(coroutine.create(function()
-- a coroutine lets us simulate multithreading in roblox, allowing this loop to run while the wait waits.
while Clone.Parent do
wait()
Clone:TranslateBy(Vector3.new(0.5, 0, 0))
end
end))
wait(300) --wait however long
Clone:Destroy()
end