Should be a final question for a while. I have a gui that can change the players camera while driving. However, when you spawn more of the train, it messes up the camera. It's alright if its one train, but if you spawn more of the same then it gets messy.
Here is the camera script:
local CameraViewButton = script.Parent local Camera = game.Workspace.CurrentCamera local CameraView = 1 local TrainSeat = script.Parent.Parent.Parent.Parent.Parent.C153.MachinistSeat local Seat = game.Players.LocalPlayer.Character.Humanoid.SeatPart function ChangeCamera(View) if View == 1 then game:GetService("RunService"):UnbindFromRenderStep("UpdateCamera") Camera.CameraType = "Custom" Camera.CameraSubject = TrainSeat elseif View == 2 then Camera.CameraType = "Watch" Camera.CameraSubject = TrainSeat.Parent elseif View == 3 then Camera.CameraType = "Scriptable" game:GetService("RunService"):BindToRenderStep("UpdateCamera", Enum.RenderPriority.Camera.Value - 1, function() Camera.CoordinateFrame = CFrame.new(Seat.Parent.Poles.Position) * CFrame.Angles(math.rad(0), math.rad(Seat.Parent.Poles.Orientation.Y + 30), math.rad(0)) end) end end function ChangeCameraView() CameraView = CameraView + 1 if CameraView == 4 then CameraView = 1 end ChangeCamera(CameraView) end CameraViewButton.MouseButton1Click:connect(ChangeCameraView)
Regen:
local Engine = script.Parent.Parent["C153"] local CloneTrain = Engine:clone() Button = script.Parent.Parent.WCSpawn function spawnTrain() if Button.BrickColor == BrickColor.new(104) then local Model = CloneTrain:Clone()--Clones the backup so the script doesn't break Model.Parent = game.Workspace --Puts the model into the game Model:MakeJoints() --Makes it so the model doesn't fall apart. Model.Bogies.SD_Bogie2:MakeJoints() Model.Bogies.SD_Bogie:MakeJoints() Button.BrickColor = BrickColor.new(26) wait(45) Button.BrickColor = BrickColor.new(104) end end script.Parent.ClickDetector.MouseClick:connect(spawnTrain)
Help appreciated.
Thanks for reading.
You can add a variable that determines whether or not the camera can be changed.
local Occupied = false function ChangeCameraView() if not Occupied then -- if occupied is false then Occupied = true -- sets it to true so it can't be run again CameraView = CameraView + 1 if CameraView == 4 then CameraView = 1 end ChangeCamera(CameraView) end end
I think It's something to do with the TrainSeat variable. It says in the output it isn't a part of player.