Chat spell that makes a player invisible

Hello scripters ! I’m new to scripting on roblox and since I can’t hire a scripter I decided to take matters into my own hands. I learned some code and now I’m trying to make a spell that makes the player invisible once they say it. I’ve used a similar script to make parts invisible but I want to make it work on players. The output shows no errors but the script doesn’t work.

Can someone please help me out? All help is very appreciated!

this is the script that I’m using btw

    local Player = game.Players.LocalPlayer

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "invisique" then
		
		Player.LeftFoot.Transparency = 1
		Player.LeftHand.Transparency = 1
		Player.LeftLowerArm.Transparency = 1
		Player.LeftUpperArm.Transparency = 1
		Player.LeftUpperLeg.Transparency = 1
		Player.RightFoot.Transparency = 1
		Player.RightHand.Transparency = 1
		Player.RightLowerArm.Transparency = 1
		Player.RightUpperArm.Transparency = 1
		Player.RightUpperLeg.Transparency = 1
		Player.LowerTorso.Transparency = 1
		Player.UpperTorso.Transparency = 1
		Player.Head.Transparency = 1
		Player.HumanoidRootPart.Transparency = 1
		Player.Head.Face.Transparency = 1
		Player.Accessory.Transparency = 1
		Player.Hat.Transparency = 1
	end

	wait(10) --the amount of time the player should be invisible
	
		
		Player.LeftFoot.Transparency = 0
		Player.LeftHand.Transparency = 0
		Player.LeftLowerArm.Transparency = 0
		Player.LeftUpperArm.Transparency = 0
		Player.LeftUpperLeg.Transparency = 0
		Player.RightFoot.Transparency = 0
		Player.RightHand.Transparency = 0
		Player.RightLowerArm.Transparency = 0
		Player.RightUpperArm.Transparency = 0
		Player.RightUpperLeg.Transparency = 0
		Player.LowerTorso.Transparency = 0
		Player.UpperTorso.Transparency = 0
		Player.Head.Transparency = 0
		Player.HumanoidRootPart.Transparency = 1
		Player.Head.Face.Transparency = 0
			Player.Accessory.Transparency = 0
			Player.Hat.Transparency = 0
	end)	
`end)`
4 Likes

Hello. Is this a local script or a server script? It calls for an error both locally and globally, which is kind of strange.

1 Like

I made it a server script because with a local script it would only make the player invisible for the client and not for the whole server.

That’s weird, it doesn’t call for any errors on my end yet the script doesn’t work

1 Like

First of all, the ancestry of Player’s Character is Player.Character["Body Part Name"].
And to make your script look better in advance, you could use for ~ do iteration.

local Player = game.Players.LocalPlayer

local TransparencyTable = {}
local CanTrunInvisible = true

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "invisique" and CanTrunInvisible then
			CanTrunInvisible = false
			TransparencyTable = {}
			for i, v in next, game.Players.Character:GetDescendants() do
				if v:IsA("Accessory") or v:IsA("BasePart") then
					TransparencyTable[#TransparencyTable + 1].Reference = v
					TransparencyTable[#TransparencyTable + 1].Transparency = v.Transparency
					v.Transprency = 1
				end
			end
			wait(10) --the amount of time the player should be invisible
			for i, v in next, TransparencyTable do
				v.Part.Transprency = v.Transparency
			end
			CanTrunInvisible = true
		end
	end)	
end)

3 Likes

Hey. I have detected a few errors that you need to fix for the script to work.

  • Do not call LocalPlayer on a server script, it would return an error.
  • Connect the function to everytime the character is added, as the character not being present will result in an error.
  • You need not write the code to change the transparency for every single part. Also, using this method would error in R6. Use just a for ... do loop to look through the parts which are either Part, MeshPart or UnionOperation.
  • Use the Humanoid:GetAccessories() Method to get the accessories. This ensures that all accessories are returned.
  • Accessories do not have a transparency property. Change their Handle's Transparency instead.
  • The wait() is outside the condition check, which lets it run anyway. Put that inside the conditional block.

  • I'm gonna leave my version of your script here, which might help you understand it a bit better.

    Parent this to ServerScriptService.

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		Player.Chatted:Connect(function(msg)
			if msg == "invisique" then
				for _,BodyPart in pairs(Character:GetChildren()) do
					if BodyPart:IsA("Part") or BodyPart:IsA("UnionOperation") or BodyPart:IsA("MeshPart") then
						BodyPart.Transparency = 1
					end
				end
				
				for _,Accessory in pairs(Humanoid:GetAccessories()) do
					Accessory.Handle.Transparency = 1
				end
				
				wait(10)
				
				for _,BodyPart in pairs(Character:GetChildren()) do
					if BodyPart:IsA("Part") or BodyPart:IsA("UnionOperation") or BodyPart:IsA("MeshPart") then
						if BodyPart.Name ~= "HumanoidRootPart" then BodyPart.Transparency = 0 end
					end
				end

				for _,Accessory in pairs(Humanoid:GetAccessories()) do
					Accessory.Handle.Transparency = 0
				end
				
			end
		end)	
	end)
end)


Keep up the scripting. You're getting better and better at it!

3 Likes

thank you so so much! I don’t really understand tables and etc yet so the script looks a little confusing to me.

I’ve received another script which also worked so thanks to you both for your help!

2 Likes

I just tried it and it works!

Thank you so much for your help and the tips, I really appreciate it!

2 Likes

hey! if it’s not too much of a bother, could you help me with the face transparency? I tried something but it didn’t work.

1 Like

Hello. You can set the ImageLabel of the face’s Visible property to false.

2 Likes

I tried this and it told me that I attempted to index nil with ‘Visible’. What should I do?

1 Like

I think that you need to do reference it as Character.Head.Face outside both the for... do loops.

3 Likes