Hi folks, I have been at this time and time again and can't understand how to fix what I'm doing wrong. The problem is that the button (After making it's first copy of the train from ServerStorage) continues to flash from red to green and vice versa within the given time on line 9. I know exactly what the problem is and have attempted several fixes, but neither work. The problem is there are no copies of the train to start off with in Workspace, so upon pressing the button, it makes a copy, waits until the train is 14 studs away and goes back to green to allow another copy to be made. Only when you click it the second time, it continues to flash red and green. Please have a look below:
script.Parent.ClickDetector.MouseClick:Connect(function(Duplicate)
local n = game.Workspace:FindFirstChild("Train")
if (n == nil or (script.Parent.Position - script.Parent.Parent.Train.DriverSeat.Position).magnitude > 14) then
script.Parent.BrickColor = BrickColor.new("Crimson")
local c = game.ServerStorage.Train:Clone()
c.Parent = game.Workspace
c:MakeJoints()
while true do
wait(0.5)
if (n == nil or (script.Parent.Position - c.DriverSeat.Position).magnitude > 14) then
script.Parent.BrickColor = BrickColor.new("Parsley green")
else
script.Parent.BrickColor = BrickColor.new("Crimson")
end
end
end
end)
Thank you so much for taking the time to read, and if you can help me, that would be greatly appreciated.

2 comments
Thanks so much, this has helped me out a ton with my new game. Thank you also for doing a working demonstration, if I could give you extra points I would gladly do that. Best regards, DeanozDezignz.
No problem. I look forward on playing your game