Hey, so I made a spectate script and I was trying to make it only for people who are in the lobby.
What I did is remove the gui from the person if the player is not on the lobby team then clone it back to them once the round is over
but I got an error telling me that SpectateGui is not avaliable in ServerStorage even though it is in ServerStorage.
local player = game.Players.LocalPlayer
local team
local camera = game.Workspace.CurrentCamera
local spectate = script.Parent:WaitForChild("Spectate")
local lobbyTeam = game:GetService("Teams").Lobby
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local contestants = {}
local current = 1
local maxContestants = 0
game:GetService("RunService").RenderStepped:Connect(function()
contestants = {}
for i,v in pairs(game.Players:GetChildren()) do
table.insert(contestants,v)
end
for _,plr in pairs(Players:GetChildren()) do
if plr.Team ~= lobbyTeam and ReplicatedStorage.InRound.Value == true then
local spectate = plr.PlayerGui.SpectateGui
spectate:Destroy()
elseif ReplicatedStorage.InRound.Value == false then
local spectateClone = game:GetService("ServerStorage").SpectateGui:Clone()
for i,v in pairs(game:GetService(“Players”):GetChildren()) do
if v.PlayerGui.SpectateGui then
v.PlayerGui.SpectateGui:Destroy()
end
end
spectateClone.Parent = plr.PlayerGUI
end
end
camera.CameraType = Enum.CameraType.Follow
if #contestants <= maxContestants then
spectate.SpectateFrame.Visible = false
camera.CameraSubject = player.Character.Humanoid
end
if spectate.SpectateFrame.Visible == true then
local playerSpectating = contestants[current]
if not playerSpectating then playerSpectating = contestants[1] end
local char = playerSpectating.Character
if char and char:FindFirstChild("Humanoid") then camera.CameraSubject = char:FindFirstChild("Humanoid") end
spectate.SpectateFrame.Current.Text = playerSpectating.Name
elseif spectate.SpectateFrame.Visible == false then
camera.CameraSubject = player.Character.Humanoid
end
end)
spectate.SpectateButton.MouseButton1Click:Connect(function()
if #contestants <= maxContestants then return end
if player.Team ~= lobbyTeam then return end
if player.Team == lobbyTeam then
spectate.SpectateFrame.Visible = not spectate.SpectateFrame.Visible
end
end)
spectate.SpectateFrame.Back.MouseButton1Click:Connect(function()
if current == 1 then
current = #contestants
else
current -= 1
end
end)
spectate.SpectateFrame.Fwd.MouseButton1Click:Connect(function()
if current == #contestants then
current = 1
else
current += 1
end
end)