I made a script that when you click the gui button Outfit, the whole gui clears from the screen and then the camera position changes to the brick name CameraForOutfit. The gui closing part works but the camera changing role doesnt. I am getting a message saying that the part CameraForOutfit is not a valid member of workspace. Whats wrong with the code? Thanks
local Camera = workspace.CurrentCamera script.Parent.MouseButton1Click:connect(function() script.Parent.Parent:Destroy() Camera.CameraType = Enum.CameraType.Scriptable Camera.CFrame = workspace.CameraForOutFit.CFrame end)
You need to update the CFrame of the camera. You can use BindToRenderStep
that way you can stop the updating at a later point.
Also I'm going to be using some part I had in workspace as a test example. You would need to edit the script to your liking, but the idea is the same.
local RunService = game:GetService("RunService") --RunService to get BindToRenderStep local camera = workspace.CurrentCamera --Our camera, we're in a local script local offset = Vector3.new(5,5,5) --some offset we'll add to our camera's Pos function updateCam() --This will position the camera to the Part and add and offset --It will also make the camera focus/lookAt the part camera.CFrame = CFrame.new(workspace.Part.Position + offset, workspace.Part.Position) end script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent:Destroy() camera.CameraType = Enum.CameraType.Scriptable --camera.CameraSubject = workspace.Part --Not sure if this is needed RunService:BindToRenderStep("CameraToOutfit", 1, updateCam) end) --[[ Other notes: In some other function you can call :UnbindFromRenderStep("CameraToOutfit") to stop the updating. You will need to reset the camera to the default though. ]]
More useful stuff on BindToRenderStep.