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 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.
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)