Player Visibility

Hey, I'm currently trying to figure out a way to make my player invisible. In another forum it said to put the code:
player:SetVisibility(false)

I tried using that code but it kept coming up with the error:
Error running Lua task: [9EBA91F3DACCB13C] InvisScript:1: attempt to index a nil value (global 'player')

How do I fix this? Is there another way to make my player invisible?

Hi, Raiin! Sorry for the delayed response.

The error message you're getting is telling you that you're trying to use a variable (player) that hasn't been assigned yet. You're trying to call the correct function, you just need a reference to the player you want to call it on. Usually things that affect a player are done in response to some event, such as the player joining the game or interacting with a trigger. For example, to make all players invisible when they join the game, you might do the following:

function HandlePlayerJoined(player)
  player:SetVisibility(false)
end

Game.playerJoinedEvent:Connect(HandlePlayerJoined)

Or to change the player's visibility when they enter or exit a Trigger volume, you might add this script as the child of a Trigger:

function HandleBeginOverlap(trigger, other)
  if other:IsA("Player") then
    other:SetVisibility(false)
  end
end
function HandleEndOverlap(trigger, other)
  if other:IsA("Player") then
    other:SetVisibility(true)
  end
end
script.parent.beginOverlapEvent:Connect(HandleBeginOverlap)
script.parent.endOverlapEvent:Connect(HandleEndOverlap)

It's ok! Thank you so much for the help, it works perfectly!