Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't the property 'visible' work on my gui?

Asked by 4 years ago
Edited 4 years ago

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!

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Two fundamental problems here:

  1. 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.

  2. 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)
0
I'm sorry if I'm bothering you, but - Please could you help me make it so the team changes only when you press confirm? I tried doing it but it won't work... ISkyLordDoge 37 — 4y
Ad

Answer this question