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

Camera movement question. How can i do it?

Asked by 6 years ago

I want to make something that when a play touches a part or clicks a button , their camera moves to an exact position, and they can't move it, and when they press a button their camera reverts to normal.

0
You're lucky you got help because requesting is not allowed, Ady LordTechet 53 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
01wait() --Waits for player to load
02 
03function MoveCamera(cframe, button)
04    local prevCFrame = game:GetService("Workspace").Camera.CFrame
05    local camType = game:GetService("Workspace").Camera.CameraType
06 
07    game:GetService("Workspace").Camera.CameraType = Enum.CameraType.Scriptable --Disables player moving camera
08 
09    game:GetService("Workspace").Camera.CFrame = cframe --Set camera position
10 
11    buttonEvent = button.MouseButton1Click:connect(function() --Change 'MouseButton1Click' to 'MouseClick' if using ClickDetector
12        game:GetService("Workspace").Camera.CameraType = camType
13        game:GetService("Workspace").Camera.CFrame = prevCFrame
14        pcall(function() --Incase of error
15            buttonEvent:Disconnect() --Disconnects event from function so it only runs once
16        end)
17    end)
18end
19 
20--e.g. MoveCamera(CFrame.new(0, 10, 0), GuiButton)

edit:

1local prevCFrame = game:GetService("Workspace").Camera.CFrame
2local camType = game:GetService("Workspace").Camera.CameraType

Stores the players camera data.

1game:GetService("Workspace").Camera.CameraType = Enum.CameraType.Scriptable

Removes the ability for the player to move the camera.

1game:GetService("Workspace").Camera.CFrame = cframe

Sets the camera cframe to the one used in the function.

1game:GetService("Workspace").Camera.CameraType = camType
2game:GetService("Workspace").Camera.CFrame = prevCFrame

Sets the camera data back to before it was changed, fixes the camera.

1buttonEvent:Disconnect()

Disconnects the event so it cannot run again.

Hopefully the edit helps.

0
pls explain not in comments User#24403 69 — 6y
Ad

Answer this question