Script error saying player is nil?

Hello! I’m having a problem. I’m trying to make it so if a player hits an object, a remote event fires. It works the first time, but I get an error the second time? It looks like the output is saying that the player is nil again. That doesn’t make sense. Here’s the code and the error message. If anyone could help out, that’d be awesome. Thanks!

local player = game.Players:GetPlayerFromCharacter(hit.Parent)
task.wait(1)
if player ~= nil then
	print(player.Name.." 1")
	game.ReplicatedStorage.CameraEvent4:FireClient(player)
end

Probably because you told the script that hit.Parent was a player. Not always it is.

probably because the hit isn’t a player

What am I supposed to do then?

Add checks if the hit is actually the player

It works, thanks for responding!

1 Like

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