Hello, Im trying to make first person camera script ontouch, but don't work. Please help me with it.
1 | function OnTouch() |
2 | local player = game.Players.LocalPlayer |
3 | player.CameraMode = 0 |
4 | wait() |
5 | player.CameraMode = 1 |
6 | end |
7 |
8 | 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:
1 | 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. |
2 | local player = game.Players:GetPlayerFromCharacter(part.Parent) --The function used. Make sure it targets the player's model, not just an individual part. |
3 | if player ~ = nil then --We check if there indeed is a player controlling that part. |
4 | player.CameraMode = "LockFirstPerson" --Or you can use Enum.CameraMode.LockFirstPerson |
5 | end |
6 | end |
7 |
8 | script.Parent.Touched:connect(OnTouch) |