Camera CFrame changing for everyone in the server

I am making this game where when you enter a room the camera changes to the room for you with a part touch. but it changes for everyone in the server.
for example if i am at spawn and someone else enters another room, everyone’s camera gets changed to the room that one player has accessed. how can i change it so it only changes the camera for one player?

its a local script inside of starter Gui.
this is my script:
(btw not the full script)

local camera = workspace.Camera
local player = game.Players.LocalPlayer
local camMain = workspace.Cams.camMain

s2.Touched:connect(function(touched)
	if touched.Parent:FindFirstChild("Humanoid") then
		camera.CFrame = camMain.CFrame
	end
end)

I believe it is because .Touched is fired for everyone

how can i make it to be only for one player
is there a function only for the player

would i have to get a romote event?

I understand that now the event touched will be triggered for any player who touched it, so you need to check if the player who touched it is the same as the local player.

1 Like

is it possible to send information to other scripts like what player touched the block?

how do i check that? and what is the diffrence.(sry im new to lua code)

The difference is that now only the camera CFrame of the player who touched it will change.

In this example I provided, it will compare if the player UserId who touched the part is the same as the local player UserId and if that is true, it will change the CFrame of the camera.

local camera = workspace.Camera
local player = game.Players.LocalPlayer
local camMain = workspace.Cams.camMain

s2.Touched:connect(function(touched)
	if touched.Parent:FindFirstChild("Humanoid") then
		local hitplayer = game.Players:GetPlayerFromCharacter(touched.Parent)
		if hitplayer.UserId == player.UserId then
			camera.CFrame = camMain.CFrame
		end
	end
end)
3 Likes