Hello. I’m making a change team GUI. And I have a couple of teams that are staff only. I would like to try and make it so that if you’re in a group or multiple of the extra group the text button would appear. If not it would destroy the button only not the whole GUI.
Here’s the script: script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.TestButton.Visible = not script.Parent.Parent.Frame.Visible
end)
if game.Players.LocalPlayer:GetRankInGroup(4403130) < 2 then
script.Parent.Parent:Destroy()
end
It always for some reason destroys the whole UI not just the text button. Could I get some help?
if game.Players.LocalPlayer:GetRankInGroup(4403130) < 2 then
script.Parent.Parent.TestButton:Destroy()
end
The issue is that you were calling :Destroy() on the UI, not the button.
Also, I’d recommend checking the group rank on the server too before letting them pick the team to prevent exploiters from being able to get the ranks without the role if you’re not already.
FindFirstChild should only be used if it’s not guaranteed the object you’re looking for exists.
If the object doesn’t exist, it just returns nil, and calling :Destroy() on nil will also just result in an error. All it’s doing is adding unneeded extra time to process the script.
I believe the issue is you did < instead of <= so Roblox just destroyed the gui.
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.TestButton.Visible = not script.Parent.Parent.Frame.Visible
end)
if game.Players.LocalPlayer:GetRankInGroup(4403130) < 2 then
script.Parent.Parent:Destroy()
end
Bit of an off-topic response, however I’d like to clarify that no, FindFirstChild can have a multitude of uses outside of being used only “if it’s not guaranteed the object you’re looking for exists”
Certainly one is for your own sanity, for example: