Touched Not Working

I am trying to make the camera change to a certain object when they touch a part, I have this code and it wont work… I have no error untill I leave the game. This is the error ServerScriptService.CutsceneTrigger:18: attempt to index nil with 'Humanoid' and I have no idea why this wont work.

local Players = game:GetService("Players")
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
debounce = false

function Trigger1()
	if debounce == false and player:FindFirstChild("Humanoid") then
		debounce = true
		repeat wait() until player.Character 
		cam.CameraType = "Scriptable" 
		cam.CFrame = workspace.CutsceneCamera.CamPart.CFrame
		wait(6)
		cam.CameraSubject = player.Character.Humanoid
		cam.CameraType = "Custom"
		cam.CFrame = player:FindFirstChild("Head").CFrame
		wait(10)
		debounce = false
	end
end
workspace.CamTrigger1.Touched:Connect(Trigger1)

This script is in a LocalScript in ServerScriptService could anyone help me?

Here are some images of where thing’s are in my game.
image
image

Servers use Script, not LocalScript.
LocalScript doesn’t work on ServerScriptService, which can be found out by a simple printf

print("This won't print on LocalScripts in ServerScriptService");
1 Like

I would move the LocalScript to StarterPlayerScripts.

1 Like

The part where you are trying to use FindFirstChild looks like you’re trying to find Humanoid in a Player and not a Character.

Instead replace function Trigger1() with function Trigger1(hit). That way, you’re able to find the player using hit.Parent and find the Humanoid there.

Or instead of player:FindFirstChild(), use player.Character:FindFirstChild()

2 Likes

Awsome! This works thanks :slight_smile:

1 Like