Enabling UI from Local Script not working

Hello! I am currently working on the main menu for my game and I have came across an issue. I have made it so in order to join a certain team you must be a certain rank in a group. When you aren’t in the group and you try to join that team it will team you to the neutral team, refresh you, and re-enable the main UI for you to be able to re-select their team. All of it works except for re-enabling the UI. Basically, a remote event is fired from the original LocalScript to the server, in the server script it checks the group rank and if you do not meet the rank requirements it teams the player to the neutral team and refreshes them. It also fires another RemoteEvent back to the LocalScript. When the event is fired, it should re-enable the main UI, but that doesn’t seem to happen. I have tried changing other properties such as the name and that worked but I can’t seem to change the “Enabled” property to true. Some help would be appreciated, I linked the important parts of the scripts below. If you have any questions, please ask…

Initial Local Script:

teamselect:FireServer(CurrentClassSelected)
					menuMusic:Stop()
					task.wait(0.1)
					Background.Enabled = false
					ScreenGui.Enabled = false

Server Script:

local players = game.Players
local mainGroup = 14547833




function resetGui(plr)
	game:GetService("ReplicatedStorage"):WaitForChild("NotAllowedTeam"):FireClient(plr)
	print("Event fired, player not allowed on team.")
end

game.ReplicatedStorage.TeamSelect.OnServerEvent:Connect(function(plr,team)
	
	if  game:GetService("Teams"):FindFirstChild(team) then -- Handles Team Change from main GUI
		plr.Team = game:GetService("Teams"):FindFirstChild(team)
		plr.Neutral = false
		plr:LoadCharacter()
		
		-- Checks for group rank dependant on team.
		
		if plr.Team == game:GetService("Teams")["Administrative Department"] and plr:GetRankInGroup(mainGroup) < 16 then plr.Team = game:GetService('Teams')["Class - D"]
			plr:LoadCharacter()
			resetGui(plr)
		end
		
		if plr.Team == game:GetService("Teams")["Engineering & Technical"] and plr:GetRankInGroup(14551179) > 1 then plr.Team = game:GetService('Teams')["Class - D"]
			plr:LoadCharacter()
			resetGui(plr)
		end
		
		if plr.Team == game:GetService("Teams")["Foundation Personnel"] and plr:GetRankInGroup(mainGroup) < 10 then plr.Team = game:GetService('Teams')["Class - D"]
			plr:LoadCharacter()
			resetGui(plr)
		end
		
		if plr.Team == game:GetService("Teams")["Medical Department"] and plr:GetRankInGroup(14551193) < 1 then plr.Team = game:GetService('Teams')["Class - D"]
			plr:LoadCharacter()
			resetGui(plr)
		end
		
		if plr.Team == game:GetService("Teams")["Mobile Task Force"] and plr:GetRankInGroup(14551183) < 1 then plr.Team = game:GetService('Teams')["Class - D"]
			plr:LoadCharacter()
			resetGui(plr)
		end
		
		if plr.Team == game:GetService("Teams")["Research Department"] and plr:GetRankInGroup(14552211) < 1 then plr.Team = game:GetService('Teams')["Class - D"]
			plr:LoadCharacter()
			resetGui(plr)
		end
		
		if plr.Team == game:GetService("Teams")["Security Department"] and plr:GetRankInGroup(14551187) < 1 then plr.Team = game:GetService('Teams')["Class - D"]
			plr:LoadCharacter()
			resetGui(plr)
		end
		
		if plr.Team == game:GetService("Teams")["Site Director"] and plr:GetRankInGroup(mainGroup) < 30 then plr.Team = game:GetService('Teams')["Class - D"]
			plr:LoadCharacter()
			resetGui(plr)
		end
		
		
		
	end
	
end)

LocalScript (the one with the problem)

game:GetService("ReplicatedStorage"):WaitForChild("NotAllowedTeam").OnClientEvent:Connect(function(plr)
	print("Received")
	game:WaitForChild("Players").LocalPlayer.PlayerGui.MENU.Enabled = true
end)

Hi! I wouldn’t be able to give you a plug-and-play answer, but here is the approach you have to follow.

I’ve used a “Button” as a sample to how you could send the remote. :slight_smile:

  • Make a local script. (Make the Parent the GUI you want to fiddle with for the sake of simplicity).
  • In the localscript, make sure to make variables for all the stuff. Just a very good practice!
--LocalScript
local Gui = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("Remote")
local Button = Gui:WaitForChild("Button")
local ButtonTeam = Button:GetAttribute("TeamToJoin")
local DebounceWait = 2

local ButtonDebounce = false
Button.Activated:Connect(function()
	if not ButtonDebounce then
		ButtonDebounce = true
		if ButtonTeam then
			Remote:FireServer(Team)
		end
		task.wait(DebounceWait)
		ButtonDebounce = false
	end
end)


Remote.OnClientEvent:Connect(function(status)
	if status then
	-- We sent a Status value from server, if True, then they're allowed to join the team. (Just for checking or if you want anything else to happen for client, when they join the team)
		if Gui.Enabled then
			Gui.Enabled = false
		end
	else
		-- Do all your reset stuff for client in here :)
		if not Gui.Enabled then
			Gui.Enabled = true
		end
	end
end)

Now lets go into the server script, we need our OnServerEvent listener!

--ServerScript
local MarketPlaceService = game:GetService("MarketPlaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("Remote")
local TeamGamepass = 23892873237 -- Your Gamepass ID

local function ownsgamepass(userid,gamepassid)
	local s,res = pcall(MarketPlaceService.UserOwnsGamePassAsync,MarketPlaceService,userid,gamepassid)
	if not s then
		res = false
	end
	return res
end

Remote.OnServerEvent:Connect(function(Player, Team)
	local UserID = Player.UserId
	if ownsgamepass(UserID, TeamGamepass) then
		-- Stuff you want the player to have, when they have the gamepass
		Remote:FireClient(Player, true)
	else
		-- Stuff you don't want the player to have, when they don't have the gamepass
		Remote:FireClient(Player, false)
	end
end)

I’m not sure why you included gamepasses? The server script checks if the player is in a group or not. Everything works except enabling the UI, the menu works just fine.

Sorry! Instead of Gamepass, just insert the GroupRankID, and check if player has that Rank.

But to your script.

Have you tried toggling off “ResetOnSpawn” in the gui?

Yes, the UI has that off, I’m not sure what’s wrong.

Oh another thing! go add a dictionary with all your values, instead of having a lot of “if statements” :smiley:

-- Just change it to your liking, I just set the GroupRankID to the thing we're looking for! :D
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeamSelectRemote = ReplicatedStorage:WaitForChild("TeamSelectRemote")
local Teams = game:GetService("Teams")
local MainGroupID = 238329389238 -- Your Group id!
local SecondaryGroupID = 238329389238 -- Your Group id!
local RankTable = {
	["Administrative Department"] = {GroupID=MainGroupID,MinimumRankIDNeeded=126,TeamCategoryClass="Class - D"};
--["Template Team"] ={GroupID=SecondaryGroupID,MinimumRankIDNeeded=0,TeamCategoryClass="WhichClass?"}; -- Template for you!
}

TeamSelectRemote.OnServerEvent:Connect(function(Player, Team)
	if RankTable[Team] then
		local PlayersCurrentGroupRank = Player:GetRankInGroup(RankTable[Team]["GroupID"])
		if PlayersCurrentGroupRank > RankTable[Team]["MinimumRankIDNeeded"] then
			print("PLAYER GOT ON THE SELECTED TEAM! :D")
			TeamSelectRemote(Player, true) -- They got on the team! :D
			Player.Team = Teams[RankTable[Team]["TeamCategoryClass"]]
			Player:LoadCharacter()
		else
			print("PLAYER DID NOT GET ON THE SELECTED TEAM :(")
			TeamSelectRemote(Player, false) -- They didn't get on the team! :(
		end
	else
		print("PLAYER DID NOT GET ON THE SELECTED TEAM :(")
		TeamSelectRemote(Player, false) -- They didn't get on the team! :(
	end
end)

Sorry if there’s any spelling errors!

Also see if get any prints from when they’ve selected a team that works, and a team that doesn’t work, so you know if everything detects correctly! (Added the prints for you)

  • It could be optimized slightly, in the way that false remote could be only written 1 time in the script, but it does not matter much in this case! :smiley:

Thanks for the feedback. Yes, everything works, including all of the events being fired, except for enabling the UI.

On your own script, or the one I just posted?

On my own script. I need so many characters to post apparently.

Please try mine out. Save a copy of your current Server “Remote” Script. If mine fails(and you see no error, and a output with that they got on the team in played in the output, then it’s on the client side something is messed up, if that is the case, make a new localscript with a gui, and try to “enable/disable” it through TeamRemote.OnClientRemote, with the value you get from the serverScript (it will be either true or false))

I tried yours and the same issue is happening. Everything works, including all of the RemoteEvents because if they aren’t in the group they get re-teamed. The only issue is that the UI simply can’t be enabled from the local script for some reason. I have tried game.Players.LocalPlayer.PlayerGui.Menu.Enabled = true, and many alterations and none of them seem to work for some reason.

No errors? Also make sure to use “WaitForChild” for objects on the client.

Nope, no errors whatsoever. Here’s the bit of code for that:

game:GetService("ReplicatedStorage"):WaitForChild("NotAllowedTeam").OnClientEvent:Connect(function(plr)
	print("Received")
	game:WaitForChild("Players").LocalPlayer.PlayerGui.MENU.Enabled = true
end)

Does it print “Received”? Sorry if you’ve told me already

Yes, it prints received. I also tried to change another property of the UI such as the name, it worked when testing, but when I try to enable it, nothing happens.

When test playing, go into Players, go into PlayerGui, and check if the gui is changing "Enableility"or not, when you fail to select team

Nope, nothing changes but there isn’t an output either.

You just told me that it printed Received in the output? or did we talk past each other?

Yes, it prints received, I meant there isn’t any errors in the output, my bad.

Try print this, right before the “Received” print

print(game:WaitForChild("Players").LocalPlayer.PlayerGui.MENU)