Why won't "game.Players.PlayerAdded:Connect(function(player)" work?

Hello, I am trying to check if the player that just joined is a mod in my group. Here is what I did.

game.Players.PlayerAdded:Connect(function(player)
print(“Checking rank…”)
if player:GetRankInGroup(12563062) >= 100 then
panelButton.Visible = true
print(“Is mod.”)
else
panelButton.Visible = false
print(“Isn’t mod.”)
end
end)

This is in a local script in my moderation panel GUI. The script is called “Handler”. I’m trying to check if the player that just joined is a certain rank in my group. In the output, it’s not even putting “Checking Rank…”
image

2 Likes

Did you try in roblox studio, if so, try in game, it sometimes doesn’t work very well in studio.

1 Like

Oh, I didn’t try in-game. I’m going to do that now.

1 Like

Another reason would be because you are trying to detect when you join, to do that just do it with game.Players.LocalPlayer instead

1 Like

I tried it in game and it didn’t work. Also, I’m not sure what you mean by do it with game.Players.LocalPlayer.

1 Like

I would highly suggest you would make it into a script in serverscriptservice, put the UI inside of it, then clone the UI into the plr that joined’s playergui if it meets the requirements to prevent exploiters from getting access to the panel by just making it visible.

1 Like

I’m not even sure how to put the UI inside of the player.

1 Like

here is a code that would do it all, make sure to put the Mod UI inside of the script:
(Make a script with this into the serverscriptservice)

local UI = script:WaitForChild("ModPanel")
game.Players.PlayerAdded:Connect(function(player)
    print("Checking rank…")
    if player:GetRankInGroup(12563062) >= 100 then
        local UIClone = UI:Clone()
        UIClone.Parent = player.PlayerGui
        print("Is mod.")
    else
        print("Isn’t mod.")
    end
end)
4 Likes

Would I make it a regular script or local script?

1 Like

Make it a regular script (End of the sentence)

1 Like

Oh I forgot to mention it, but you need to make the panel button visible “In the properties (Not the script)”

1 Like

Last question (Sorry, I just kinda started and have many questions.)
So, inside of the the GUI I have many other frames that I make visible if the user clicks a button.
Would I just do UI.Menu.Visible = true ?

2 Likes

image

1 Like

No, just make localscript(s) inside the ui that will detect clicks and make the frames visible.

2 Likes

Cloning UIs from server scripts still runs the localscripts inside of them.

2 Likes

Okay, thanks for your help!
I’ll add you on the double XP list if you ever find the game and play it in the future.

1 Like

Oh alr thanks, I appreciate it.

2 Likes

Why are you adding a PlayerAdded event to a LocalScript? This is going to make it visible for everyone else who joins if somebody with that rank joins, and wouldn’t even fire for you as the UI is replicated onto the client after you join.

local player = game.Players.LocalPlayer
local panelButton = script.Parent:WaitForChild('ModerationPanel')

if player:GetRankInGroup(12563062) >= 100 then
panelButton.Visible = true
print("Is mod.")
else
panelButton.Visible = false
print("Isn’t mod.")
end

Is all you need in your LocalScript.

3 Likes

(This only applies to the local version Zivao sent, not the serversided one)
If Corey doesn’t make checks for his admin actions buttons (such as check the plr’s group rank everytime he uses the admin event), exploiters will be able to use them by just making the frame visible.

2 Likes

Yea, I recommend you also secure your serversided events and don’t rely on frame visibility because you might as well make it accessible for everybody if you’re going to do that.

1 Like