spectateClone not a valid member of ServerStorage

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)

This is because you cannot access the ServerStorage on the client, you would need to move the spectate clone to somewhere that the client can access.

1 Like

What service can I access in a local script?

i would usually store them inside of ReplicatedStorage since both the server snd client can access it

i also do store my ui components inside of repstorage

1 Like