Script doesn't load up at all

Hi!

I’m on a Roblox dev camp and want to lock the player’s camera in first-person mode when they enter a certain area.

I put in a part with CanCollide turned off and a local script inside the part that, when touched, should set the player’s CameraMode to LockFirstPerson, however when testing it I found out the script wouldn’t start at all.

I tried moving the script into ServerScriptService and coding it so that it’d find the part from there, but it didn’t work either.

The code is as follows:

local playerService = game:GetService("Players")
local player = playerService.LocalPlayer

script.Parent.Touched:Connect(function()
	player.CameraMode = Enum.CameraMode.LockFirstPerson
end)
1 Like

off topic but how do you know that its the player touching the part and not some other player or another object?

is the localscript perhaps in workspace?

It’s under the part.

randomstufftomatchthecharacterlimit

Could be the problem, is there a way to filter it to players only?

okay, make a LocalScript in StarterGui or in StarterPlayerScripts and paste the following script

local players = game:GetService("Players")
local player = players.LocalPlayer
local part = workspace.Part

part.Touched:Connect(function(Touch)
	local playerTouching = players:GetPlayerFromCharacter(Touch.Parent)
	if playerTouching then
		if playerTouching == player then
			player.CameraMode = Enum.CameraMode.LockFirstPerson
		end
	end
end)

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