-- writen by achdef --
-- local script --
local player
local team = game:GetService("Teams")
while true do
game.Players.PlayerAdded:Connect(function()
player = game.Players.LocalPlayer
if player.Team == team["Spectating"] or team.Spectating then
script.Parent.Parent.Visible = true
wait(5)
print("Success") -- for debugging
else
warn("Error") -- for debugging
end
end)
end
local players = game:GetService("Players")
local player = players.LocalPlayer
if player.Team == game.Teams.Spectating then
script.Parent.Parent.Parent.Visible = true
end
i wouldn’t wanna use this but i shortened it and added a while wait even if i didn’t want to, see if this works.
local players = game:GetService("Players")
local plr = players.LocalPlayer
while wait(2) do -- change wait time it's optional
if plr.Team == game.Teams.Spectating then
script.Parent.Parent.Parent.Visible = true
end
end
First, the while true do loop is not needed. Second, im pretty sure your error is that you’re checking if they are on spectate team immediately after they join. Maybe wait until they pick the team or die?
Try this: (not sure if it works haven’t tested it yet.)
local player = game:GetService('Players').LocalPlayer
local teams = game:GetService('Teams')
local ui = script.Parent.Parent.Parent
player:GetPropertyChangedSignal('Team'):Connect(function()
if player.Team == teams.Spectator then
ui.Visible = true
else
ui.Visible = false
end
end)
Hi! This is only my second reply to a post, but I’ll give my tips. I would check if the Team Color of the player is the same as the Team Color of the Spectating team. (I think you’re doing this on the client-side?)
local Player = game.Players.LocalPlayer
local Teams = game:GetService("Team")
local Spectating = Teams:WaitForChild("Spectating")
function CheckIfOnTeamSpectate()
if Player.TeamColor == Spectating.TeamColor then -- If the player is on the Spectating team
script.Parent.Parent.Parent.Visible = true -- Show the gui
else -- If the player isn't on the Spectating team
script.Parent.Parent.Parent.Visible = false -- Hide the gui
end
end
CheckIfOnTeamSpectate() -- Checks in the beginning of the game
Player:GetPropertyChangedSignal("TeamColor"):Connect(function() -- Connects whenever the player changes team
CheckIfOnTeamSpectate()
end)