LocalScript affects other player's cameras

I have a LocalScript in StarterCharacterScript that affects the player’s camera whenever he touches a part. The problem is that when a player touches a part other player’s cameras also change. I want to make it so that only the player that touches the part has his camera changed. Here is the script:

local door = game.Workspace.finalisland.door
local cam = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer

door.Touched:Connect(function(plr)

cam.Focus = game.Workspace.finalisland.cam1focus.CFrame
cam.CameraType = "Scriptable"
cam.CFrame = game.Workspace.finalisland.cam1.CFrame

end)

game.Workspace.finalisland.cam2trigger.Touched:Connect(function(plr)

		cam.Focus = game.Workspace.finalisland.cam1focus.CFrame
		cam.CameraType = "Scriptable"
		cam.CFrame = game.Workspace.finalisland.cam2.CFrame

end)

door.Parent.doorbefore.Touched:Connect(function(plr)

cam.CameraType = "Custom"
cam.CameraSubject = player.Character:FindFirstChild("Humanoid")

end)

game.Workspace.finalisland.cam2triggerbefore.Touched:Connect(function(plr)

cam.Focus = game.Workspace.finalisland.cam1focus.CFrame
cam.CameraType = "Scriptable"
cam.CFrame = game.Workspace.finalisland.cam1.CFrame

end)

Because every client is listening to the Touched event of door. So when one player touches the door, every client that is listening for the event will fire it.

What you could do is check if the part parameter of the Touched event that touched the door belongs to the LocalPlayer’s character.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.