How can i make other players invisible when button is clicked?

Hey Developers,

I’m owner of experience that is mostly made for photos or screenshots of avatars, and i think i a button that would make players invisible would fit perfectly and increase the experience quality.

The problem is that i really suck at scripting and have no idea how to script this button.

Basically i want the button to make players invisible for the player that clicked the button only. If there will be other players that didn’t clicked the button, then they won’t see the other players invisible. (Ask me any question if this was confusing. I will try to explain it better)

Can anyone help me please?

Thanks in advance
-jeziskrista

3 Likes

I’m just replying to my post to make it show at the top of the feed.

1 Like

Sure just put this local script inside of your button

local invisible = script.Parent

invisible.MouseButton1Click:Connect(function()

for _, p in pairs(game.Players:GetPlayers()) do

local char = p.Character or p.CharacterAdded:Wait()

local root = char:FindFirstChild('HumanoidRootPart')

if char and root then

for _, part in pairs(p.Character:GetDescendants()) do

if part:IsA('Part') or part:IsA('MeshPart') then

part.Transparency = 1

end

end

end

end

end)

Enjoy :slightly_smiling_face:

1 Like

Let me try this really quick! :grinning:

1 Like

Hey, Thanks, there’s small problem, the script works, but it makes the player that clicked the button invisible too, and when i click the button again, the players won’t be visible again. They just stay invisible. But still thanks!

1 Like

No worries! I will give you both of those things just give me a minute

1 Like

Okay, thank you so much! Take your time.

1 Like
local invisible = script.Parent

local Players = game:GetService('Players')

local LocalPlayer = Players.LocalPlayer

local Boolean = false

invisible.MouseButton1Click:Connect(function()

for _, p in pairs(Players:GetPlayers()) do

local char = p.Character or p.CharacterAdded:Wait()

local root = char:FindFirstChild('HumanoidRootPart')

if char and root and Players:GetPlayerFromCharacter(char) ~= LocalPlayer and not Boolean then

Boolean = true

for _, part in pairs(p.Character:GetDescendants()) do

if part:IsA('Part') or part:IsA('MeshPart') then

part.Transparency = 1

end

end

elseif char and root and Players:GetPlayerFromCharacter(char) ~= LocalPlayer and Boolean then

Boolean = false

for _, part in pairs(p.Character:GetDescendants()) do

if part:IsA('Part') or part:IsA('MeshPart') then

part.Transparency = 0

end

end

end

end

end)
1 Like

Let me try this out! I’ll be back in minute

1 Like

Thank you so much! This is working, just a question, when the player is visible again, there’s weird block spawned in him too.

1 Like

Game looks awesome! I’m glad I could help :slightly_smiling_face:

I wouldn’t be able to know where that block came from without seeing what spawned it inside of the player. You could try using the find all feature in Studio and type something like

Instance.new("Part")

into it to see if you find it

1 Like

THank you! I will for sure take a look into it!

1 Like

I don’t know where exactly i should find it. I can also try asking Roblox AI.

I’m sure I could find it for you but that’s only if you want to share anything with me

I can share something with you. Want to add me on discord?

This is most likely the HumanoidRootPart that is showing up. So you just need to check before setting Transparency back to 0

For Example:

if part:IsA('Part') or part:IsA('MeshPart') then

					if part.Name ~= "HumanoidRootPart" then
						part.Transparency = 0
					end
				end

Otherwise here’s the updated code:

local invisible = script.Parent

local Players = game:GetService('Players')

local LocalPlayer = Players.LocalPlayer

local Boolean = false

invisible.MouseButton1Click:Connect(function()

	for _, p in pairs(Players:GetPlayers()) do

		local char = p.Character or p.CharacterAdded:Wait()

		local root = char:FindFirstChild('HumanoidRootPart')

		if char and root and Players:GetPlayerFromCharacter(char) ~= LocalPlayer and not Boolean then

			Boolean = true

			for _, part in pairs(p.Character:GetDescendants()) do

				if part:IsA('Part') or part:IsA('MeshPart') then

					part.Transparency = 1

				end

			end

		elseif char and root and Players:GetPlayerFromCharacter(char) ~= LocalPlayer and Boolean then

			Boolean = false

			for _, part in pairs(p.Character:GetDescendants()) do

				if part:IsA('Part') or part:IsA('MeshPart') then

					if part.Name ~= "HumanoidRootPart" then
						part.Transparency = 0
					end



				end

			end

		end

	end

end)
2 Likes

Yeah, i already found a solution with the guy. Still thanks!

1 Like

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