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

How to put the player camera on a part ?

Asked by 3 years ago

I have a script where the camera need to be on a Part, but the problem is, the "Camera Part" is in ReplicatedStorage, into a model, and in a other script for every player in the game, the "model" will be Cloned and placed randomly around the map there is my script for the camera and the PlayerSpawn, PlayerSpawn is on ServerScriptService and the cameraScript is on StarterGui

local ReplicatedLobby = workspace:WaitForChild("ReplicatedLobby")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = ReplicatedLobby:WaitForChild("CameraPart").CFrame

I have put "workspace" for referencing because the Parent change when a player log, but at the begining when nobody is here, the Parent is not changing because of the event "PlayerAdded" i have put here :

game.Players.PlayerAdded:Connect(function()

    local PlaceHolders = workspace.LobbyFolderPlaceHolder
    local ReplicatedLobbyClone = game.ReplicatedStorage.ReplicatedLobby:Clone()
    ReplicatedLobbyClone.Parent = workspace
    local rand = Random.new()
    ReplicatedLobbyClone.PrimaryPart.CFrame = PlaceHolders[rand:NextInteger(1, #PlaceHolders)].PrimaryPart.CFrame

    local camera = workspace.CurrentCamera
    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = ReplicatedLobbyClone.CameraPart.CFrame


end)

Answer this question