Hello, Im trying to make first person camera script ontouch, but don't work. Please help me with it.
function OnTouch() local player = game.Players.LocalPlayer player.CameraMode = 0 wait() player.CameraMode = 1 end script.Parent.Touched:connect(OnTouch)
The Players
service has a very useful function called GetPlayerFromCharacter
. That function allows you to find out wether or not a Player
touched your brick, and who it was, by checking a Model
and connecting said Model
to an existing Player
.
You can use it in a server script inside your part:
function OnTouch(part) --The Touched event also provides what part was touched. In this case we use "part" to refer to the touched part, but it can be anything. local player = game.Players:GetPlayerFromCharacter(part.Parent) --The function used. Make sure it targets the player's model, not just an individual part. if player ~= nil then --We check if there indeed is a player controlling that part. player.CameraMode = "LockFirstPerson" --Or you can use Enum.CameraMode.LockFirstPerson end end script.Parent.Touched:connect(OnTouch)