Server script won't show/hide UI

Hi, you may be thinking: “Well duh, server-scripts can’t change UI for players.” well, I am doing it through the players PlayerGui, so that is where this question pops in.

For some reason, this script is failing to enable/disable a UI if a player is under a set perm in a datastore. I just can’t wrap my head around why it isn’t working. I’ve tried using a in-game explorer to change my perm level, i’ve tried to delete the perm all in one, etc etc. Any ideas?

Code:

local PermTable = {

["Player"] = 1,
["Moderator"] = 2,
["Administrator"] = 3

}


game.Players.PlayerAdded:Connect(function(plr)

local plrID = plr.UserId

if game.ReplicatedStorage:WaitForChild("DataFolder"):WaitForChild(plrID).Data.PermissionLevel.Value >= 2 then
	
	plr.PlayerGui:WaitForChild("KronozAdminPanel").Enabled = true
	
else
	
	plr.PlayerGui:WaitForChild("KronozAdminPanel").Enabled = false
	
end

end)

( Also instead of making a new question for this, how could I go about incorporating the PermTable and checking perms through that with the datastore values? )

So is this a serverscript inside a gui? If not where is it?

This would be a ServerScript inside ServerScriptService.Kronoz

if game.ReplicatedStorage:WaitForChild(“DataFolder”):WaitForChild(“plrID”).Data.PermissionLevel >= 2 then

This may be your issue? Are you trying to wait for a folder inside DataFolder named after the player’s UserId? If so you have put the variablename into speechmarks.

I have fixed that, but it still seems that the UI didn’t go away. Odd.

I’m updating the current code

Run prints before you turn it off or on and maybe print the permission level to see if thats the conflict.

1 Like

Running prints is a great idea. What output do you get so far?

2 Likes

ah, i’ve narrowed it down. It turns out I guess my script to change my player perm to 1 went after the script that checked player perms. My bad!

Thank you both for helping throughout this!

No problem, make sure to consistently run prints and debug before you come here! The hardest bugs can simply be solved using the basic print tool.

1 Like

Will do. Would you happen to know how to make other scripts go before the other? If that is possible or makes sense?

( in simpler terms, is there a way to have scripts go in a specific order? )

Disable all the other scripts and have a script activate them in order OR
Each script waits till a certain something is done or true.

1 Like