Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Gui Closing and Changing Camera?

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)

2 comments

0

try retyping the brick's name again

0

I tried it but the camera is not placed to the brick named CameraForOutfit. The camera just stays were the player spawned

1 answer

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.

1 comment

0

Hello thank you for replying so far everything went great with your script and updating the camera. Everything is perfect except that the camera is not focusing on the part that I want the camera to be on. The camera just goes off far away from the map, it works but how would I change it to focus on the brick. I tried changing the vectors but still nothing, thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.