I was making a Team GUI for my friend, but when I try testing it, the confirm button won't show visible when I select a team. Why is this? Scripts below:
LocalScript for the RemoteEvent:
local teamRE = game:GetService("ReplicatedStorage"):WaitForChild("teamRE") -- Remote Event local civilianColour = "White" local swatColour = "Really black" local tpdColour = "Lapis" local stColour = "Really red" local teamGUI = script.Parent.Parent local mainFrame = teamGUI.MainFrame local confirmBtn = mainFrame.confirmBtn local visibilityBtn = mainFrame.visibilityBtn local teamsFrame = mainFrame.TeamsFrame local civilianLbl = teamsFrame.civilianLbl local stLbl = teamsFrame.stLbl local swatLbl = teamsFrame.swatLbl local tpdLbl = teamsFrame.tpdLbl confirmBtn.Visible = false if mainFrame.Visible == false then mainFrame.Visible = true confirmBtn.Visible = false end civilianLbl.MouseButton1Click:Connect(function(plr) teamRE:FireServer(BrickColor.new(civilianColour)) end) stLbl.MouseButton1Click:Connect(function(plr) teamRE:FireServer(BrickColor.new(stColour)) end) swatLbl.MouseButton1Click:Connect(function(plr) teamRE:FireServer(BrickColor.new(swatColour)) end) tpdLbl.MouseButton1Click:Connect(function(plr) teamRE:FireServer(BrickColor.new(tpdColour)) end)
Server Side script for Remote Event:
local teamRE = game:GetService("ReplicatedStorage"):WaitForChild("teamRE") local confirmBtn = game:GetService("StarterGui").teamGUI.MainFrame.confirmBtn teamRE.OnServerEvent:Connect(function(plr, TeamColor) plr.TeamColor = TeamColor if confirmBtn.Visible == false then confirmBtn.Visible = true end end)
If you can help, please do! :) Thanks for response!
Two fundamental problems here:
The StarterGui isn't the actual interface players see, it is only a container of the content which is cloned to a player when they join or respawn. Changing the StarterGui affects the interface only for players that join the server after the change, not players currently in the game.
The content of StarterGui is cloned to each player but this content is local. This means it exists only for that player. It can not be referenced by the server.
The fix for this is to simply reuse the remote. You can call FireClient on the remote to notify the player to make the change locally:
local teamRE = game:GetService("ReplicatedStorage"):WaitForChild("teamRE") -- Remote Event local civilianColour = "White" local swatColour = "Really black" local tpdColour = "Lapis" local stColour = "Really red" local teamGUI = script.Parent.Parent local mainFrame = teamGUI.MainFrame local confirmBtn = mainFrame.confirmBtn local visibilityBtn = mainFrame.visibilityBtn local teamsFrame = mainFrame.TeamsFrame local civilianLbl = teamsFrame.civilianLbl local stLbl = teamsFrame.stLbl local swatLbl = teamsFrame.swatLbl local tpdLbl = teamsFrame.tpdLbl confirmBtn.Visible = false if mainFrame.Visible == false then mainFrame.Visible = true confirmBtn.Visible = false end civilianLbl.MouseButton1Click:Connect(function(plr) teamRE:FireServer(BrickColor.new(civilianColour)) end) stLbl.MouseButton1Click:Connect(function(plr) teamRE:FireServer(BrickColor.new(stColour)) end) swatLbl.MouseButton1Click:Connect(function(plr) teamRE:FireServer(BrickColor.new(swatColour)) end) tpdLbl.MouseButton1Click:Connect(function(plr) teamRE:FireServer(BrickColor.new(tpdColour)) end) -- Get our client to listen for the server teamRE.OnClientEvent:Connect(function(target) if target == "ChangeConfirmButton" the if confirmBtn.Visible == false then confirmBtn.Visible = true end end end)
local teamRE = game:GetService("ReplicatedStorage"):WaitForChild("teamRE") teamRE.OnServerEvent:Connect(function(plr, TeamColor) plr.TeamColor = TeamColor teamRE:FireClient(plr, "ChangeConfirmButton") if confirmBtn.Visible == false then confirmBtn.Visible = true end end)