Heyo need help with custom cam script

So I’m trying to make a thing that checks your level then changes the camera based on that. I have no idea because of this error please help :beg:

Script:

local player = game.Players.LocalPlayer

local Camera = game.Workspace.Camera

local c1 = game.Workspace.Cams.Cam1
local c2 = game.Workspace.Cams.Cam2
local c3 = game.Workspace.Cams.Cam3
local c4 = game.Workspace.Cams.Cam4

local bl1 = game.Workspace.Balls.Ball1
local bl2 = game.Workspace.Balls.Ball2
local bl3 = game.Workspace.Balls.Ball3
local bl4 = game.Workspace.Balls.Ball4

-------- Cameras

Camera.CameraType = Enum.CameraType.Custom

game.Players.PlayerAdded:Connect(function(player)
	if player.leaderstats.Level == 1 then
		Camera.CameraSubject = c1
	end
end)

-------- 

Error:

  18:17:52.211  leaderstats is not a valid member of Player "Players.NotAid_n"  -  Server - Main:20
  18:17:52.211  Stack Begin  -  Studio
  18:17:52.211  Script 'ServerScriptService.Main', Line 20  -  Studio - Main:20
  18:17:52.211  Stack End  -  Studio
if player.leaderstats.Level == 1 then

I’m fairly sure it needs to be:

if player.leaderstats.Level.Value == 1 then

Also to clarify this is a Script and not a local script right?

2 Likes

works, but doesnt change the player’s camera subject to be the camera (make the block into the camera)

Try if player:WaitForChild("leaderstats").Level == 1 then.

1 Like

You have to set CameraType to Scriptable.

I would recommend triggering a Remote event (Server → Client) to control the cameras, usually that’s what is done for camera manipulation

1 Like

Camera.CameraType = Enum.CameraType.Scriptable

Also Camera Manipulations has to be done in client or Local Script.

Something like this:
(Example Code)

Script:

game.Players.PlayerAdded:Connect(function(player)
if player.leaderstats.Level == 1 then
game.ReplicatedStorage.RemoteEvent:FireClient(player)
end
end)

Local Script:

local Camera = game.Workspace.Camera

local c1 = game.Workspace.Cams.Cam1
local c2 = game.Workspace.Cams.Cam2
local c3 = game.Workspace.Cams.Cam3
local c4 = game.Workspace.Cams.Cam4

local bl1 = game.Workspace.Balls.Ball1
local bl2 = game.Workspace.Balls.Ball2
local bl3 = game.Workspace.Balls.Ball3
local bl4 = game.Workspace.Balls.Ball4
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = c1
end)

@Shayan_Rulz also

Still doesnt change the player’s camera to be the brick.

Script:

local player = game.Players.LocalPlayer

local Camera = game.Workspace.Camera

local c1 = game.Workspace.Cams.Cam1
local c2 = game.Workspace.Cams.Cam2
local c3 = game.Workspace.Cams.Cam3
local c4 = game.Workspace.Cams.Cam4

local bl1 = game.Workspace.Balls.Ball1
local bl2 = game.Workspace.Balls.Ball2
local bl3 = game.Workspace.Balls.Ball3
local bl4 = game.Workspace.Balls.Ball4

-------- Cameras

Camera.CameraType = Enum.CameraType.Scriptable

game.Players.PlayerAdded:Connect(function(player)
	if player.leaderstats.Level.Value == 1 then
		Camera.CameraSubject = c1
	end
end)

-------- 

NO ERRORS tho

Camera.CFrame = c1.CFrame (Assuming that your brick is c1)

1 Like

The only way to change the player’s camera to that brick is with a localscript so I still would reccomend using a remote event

1 Like

still doesnt work and yes my brick is c1

try printing something after if player.leaderstats.Level.Value == 1 then

Here is a solution:
ServerScript:

game.Players.PlayerAdded:Connect(function(player)
if player.leaderstats.Level == 1 then
game.ReplicatedStorage.RemoteEvent:FireClient(player)
end
end)

Local Script:

local Camera = game.Workspace.Camera

local c1 = game.Workspace.Cams.Cam1 --you can add the rest of your variables too, like c2 etc

local camera = workspace.CurrentCamera 
local Run = game:GetService("RunService")
local function OnChanged()
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CameraSubject = c1
	camera.CFrame = c1.CFrame
	wait()
end
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
	Run.RenderStepped:Connect(OnChanged)
end)

https://gyazo.com/beda1222a73a8e45f0c36608b6e0f340 ← Remote Event

2 Likes

I tried this with a touch event and it worked:

https://gyazo.com/cdcddfcd1b94e993c711155deb1ee1f3

1 Like

I think id work, but one problem. Walking is diabled in the game so i can have the avatar on display while you play

You mean the player is getting in the way of the camera or something?

If so you can just teleport them somewhere when that event is triggered

no lemme show you
image
player is shown in the circle spot

1 Like

You want to teleport them to that center area when that event is triggered?

theres a spawn location that puts them in that spot. player character has nothing to do with the game, just for decoration.