Making a Character Invisible

I am trying to make the player character turn Invisible when I press the Q key but I have several errors like: The famous attempting to index with Character or directly none and it does not work …

LOCAL SCRIPT:

SERVER SCRIPT:

Any solution for the problem I am having?

LOL ah yes the Attempt to index nil with something

Pretty simple, you can’t get the LocalPlayer in a Server Script

If you use the chr variable as given in the RemoteEvent you should be fine, you’ll have to reference it as plr.Character however since it returns back the Player object and not the Character Model

2 Likes

Hey. Check this topic out. It seems to be a similar issue.

PS: Please do not create a new topic before checking whether it exists.

Thanks for answering, that’s what I was trying to figure out but I need the character model.

The first thing I notice is that you have an unneeded player variable in the Server script, LocalPlayer always returns nil if ran from a regular script, it’s only usable in localscripts

Also, the first parameter of OnServerEvent is always a player instance, you’re treating it as if it gives the player’s character

You need to get the Character from the first parameter via chr.Character in your case, making sure the Character exists before continuing, then getting the GetChildren from that and you’re good to go

Also, use v:IsA("BasePart") instead of Part so it respects classes that inherit from BasePart (Wedges, parts, meshparts, etc)

1 Like

My bad,I didnt saw that topic…

Just reference the Character like so inside your RemoteEvent and you should be all set:

local Character = chr.Character

I do recommend changing your parameter to plr instead of chr however to prevent confusion

1 Like

The “chr” is a parameter of Player. Try:

local chr2 = chr.Character:GetChildren()

1 Like

That worked fine,Thank You alot!

1 Like

You can get the player from the remote params, and then get the character.

-- server

local function MakeCharacterInvisible(char)
   for _, part in ipairs(char:GetDescendants()) do
      if part:IsA('BasePart') then
         part.Transparency = 1
      end
   end
end

m.OnServerEvent:Connect(function(player)
   local char = player.Character or player.CharacterAdded:Wait()
   MakeCharacterInvisible(char)
end)
2 Likes

Oh thank you I really didn’t know, I tried it and this works for me too, really thanks

1 Like

Just to also include one last thing, something that @GAFFAL_1236 used, I recommend using GetDescendants instead of GetChildren if you also want the accessories to go invisible, since GetChildren only gets the Instances that are directly parented to what used GetChildren on, whereas GetDescendants will get everything inside of the Instance.

But if you only want the Character’s limbs to go invisible, then you can keep using GetChildren

2 Likes

Thank you, you have also just solved the problem that the hats are not invisible although I saw it coming from several videos that I saw a long time ago but thanks now I can use that.

1 Like

Also, don’t forget the face can stay visible too. Add an extra "or part:IsA(“Decal”) to the condition.

for _, part in ipairs(Character:GetDescendants()) do
	if part:IsA('BasePart') or part:IsA('Decal') then
		part.Transparency = 1
	end
end
2 Likes