Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I remove a ScreenGui for a certain team?

This is what some guy helped me with, but it doesnt seem to work! I want to have it like: A guy is on the Bright red team, and as soon as I team him to Bright blue, the GUI needs to be gone!

for i, v in pairs (game.Players:GetPlayers()) do
 if v.TeamColor == "Bright blue" then
-- If the player is in the Bright blue team
for i, obj in pairs (v:WaitForChild("PlayerGui"):GetChildren()) do
 if obj:IsA("ScreenGui") then -- Just in case
obj:Destroy()
end
end
end
end

5 comments

1

So... where's YOUR attempt at solving the problem or at least debugging it? It's great that you're asking questions, but if you put no effort into it and have people solve every little problem you have, you're just riding off of other people's hard work.

0

I know, yet I tried to fix it myself, but it never really worked out, so I got to this script, and editted it, yet it doesnt seem to work on any possible way.

0
  • the creator gave it to me personally..So I dont really rip him off..#NoHate
0

Let's see your tried to fix it myself and we may be able to help

0

This question already has an answer. https://scriptinghelpers.org/questions/17708/-

1 answer

This should work i commented what i changed

for i, v in pairs (game.Players:GetChildren()) do --Get the Children instead
		 if v.TeamColor == BrickColor.new(23) then -- BrickColor Codes work better sometimes 23 is Bright blue
			for i, obj in pairs (v:WaitForChild("PlayerGui"):GetChildren()) do
			 if obj:IsA("ScreenGui") then
				obj:remove() --remove instead of destroy because logic
			end
		end
	end
end

2 comments

0

Don't use the same iterator (the 'i', in this example) for different 'for' loops, which is a problem I came across before. It will cause the loop to skip a few things within a table, so please change the iterator (the 'i' for both loops).

0

Also noticing, do not use 'remove' to remove a Instance anymore; It has become Deprecated; http://wiki.roblox.com/index.php?title=Remove What Deprecation is; http://wiki.roblox.com/index.php?title=Deprecation

This discussion is preserved as it was. New answers, comments, and votes are closed.