Hide GUI script isnt working very well

I have a GUI I want people only to see if theyre above a certain rank, and dont have any data in a datastore. The info for the datastore is stored in a table, so I have it do the following.

	plr.CharacterAdded:connect(function()
		local info = datastore:GetAsync(plr.UserId)
		if info[1] or plr:GetRankInGroup(3198502) <= 145 then
			event:FireClient(plr, {Request = "Hide"})
		elseif not info[1] and plr:GetRankInGroup(3198502) >= 145 then
			event:FireClient(plr, {Request = "Show"})
		end
	end)

and

function Hide(info)
	if info.Request == "Hide" then
		source.Enabled = false
	elseif info.Request == "Show" then
		source.Enabled = true
	end
end

Top one is server, bottom one is client. It still shows up for some people who shouldnt be able to see it when they spawn. Help is very much appreciated.

Why would you even store the (rank of someone in a group)? When you can just do :GetRankInGroup(GroupID)?

Also, you forgot to add the player argument to the function ‘Hide()’. Basically, your code would more likely look like this:

function Hide(plr, Info)
    if info.Request == 'Hide' then
        plr[''].Enabled = false
    else -- Write down the name of the gui inside the [].
        plr[''].Enabled = true 
    end
end

Lol I don’t store someones rank? That checks to see if someone has a certain rank before giving them the option to see it.

1 Like

And when you fire the client event, plr is not one of the parameters

Didn’t you fire the remote event with a player argument…?

And, my bad, for the first thing you noted.

When you fire a client event, you have to put in the player you want to fire to, when you do onClientEvent in client script, player is already defined.

Although guis should usually be handled on the client, I believe that in this situation it could be a good idea to have the gui in serverstorage and clone it to the correct players’ playerguis from there. This would mean that it wouldn’t exist on the clients that won’t use it (seems like it is not shown most of the time). And instead of doing these checks every time the player spawns, set the ResetOnSpawn property of the screengui false and only check when they join, or at spesific time intervals, if you want to detect possible changes in the rank. This might not really solve your problem, though, if the problem is related to the checks giving wrong results.

1 Like

Firstly, yes, you do indeed have to put the player you want to fire the event to. OnClientEvent is attached to a function, and you passed 2 arguments to that function, which is the player, and the type of request. Since you have only addressed only the first argument, ‘Info’, would actually be the player. And, would you mind print debugging? (Adding print statements to check if the code is even being ran.)

The player is not passed as an argument to functions connected to OnClientEvent. It’s only used to fire the event for the correct client. It wouldn’t make sense that a local script would get the local player as an argument from onClientEvent, because it’d be useless.

2 Likes

I will stand with the fact that you do not have to input the plr into the onClientEvent parameters, as someone who works with GUIs, and uses ClientEvents a lot, I feel you can trust me when I say this.

1 Like

Hm… Seems that I need to quit helping people with issues based on RemoteEvents. Thank you for clarifying though.

2 Likes