Problems with GUI

Hi! I’ve been trying to determine wether a player can see a TextButton or not, depending on the Team they are currently assigned to. However, it doesn’t really work. Not sure what is causing it though, as it doesn’t outprint any errors, and it’s just a simple script.

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Teams = game:GetService("Teams")
local Gui = LocalPlayer.PlayerGui:WaitForChild("SpectateMenu")
local HolderFrame = Gui.Holder
local SpectateButton = HolderFrame.SpectateButton

LocalPlayer.CharacterAdded:Connect(function()
	if LocalPlayer.Team == Teams.Dead or Teams.Spectators then
		SpectateButton.Visible = true
	elseif LocalPlayer.Team == Teams.Alive then
		SpectateButton.Visible = false
	end
end)
1 Like

maybe just have something like this:

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Teams = game:GetService("Teams")
local Gui = LocalPlayer.PlayerGui:WaitForChild("SpectateMenu")
local HolderFrame = Gui.Holder
local SpectateButton = HolderFrame.SpectateButton

local function updateButton()
    if LocalPlayer.Team == Teams.Dead or Teams.Spectators then
		SpectateButton.Visible = true
	elseif LocalPlayer.Team == Teams.Alive then
		SpectateButton.Visible = false
	end
end

updateButton()
LocalPlayer.CharacterAdded:Connect(updateButton)
LocalPlayer:GetPropertyChangedSignal('Team'):Connect(updateButton)

2 Likes

Thanks for the help, tho it still doesn’t work. It doesn’t outprint any errors, which is weird.

The error might be that the script thinks you’re asking if Teams.Spectators and not if player is spectators team.

Change the line with this:

your line:
    if LocalPlayer.Team == Teams.Dead or Teams.Spectators then
corrected line:
    if LocalPlayer.Team == Teams.Dead or LocalPlayer.Team == Teams.Spectators then

If this doesn’t work, it might be you defining the frames wrongly

1 Like

Oh, yes! Thank you so much. I don’t know how I didn’t notice this by myself…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.