Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Gui Closing and Changing Camera?

Asked by 5 years ago

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)
0
try retyping the brick's name again User#23365 30 — 5y
0
I tried it but the camera is not placed to the brick named CameraForOutfit. The camera just stays were the player spawned Flognaw3210 25 — 5y

1 answer

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
5 years ago
Edited 5 years ago

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.

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. Flognaw3210 25 — 5y
Ad

Answer this question