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

Players that are not on the team screen are showing up in the *waiting for players 1/8* label?

Asked by 4 years ago

Hello, I am trying to make it so that when a player enters the team screen it would update the wait for players label. Example: Waiting for players 1/8, while on the team screen, another player joins the team screen . Waiting for players 2/8 etc and also when they leave the team screen they are kicked and the label updates to, Waiting for players 1/8.

I am currently trying a remote event but for some reason it is not working. Also I don't know if this should be client to server or server to client.

Client script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local teamEvent = ReplicatedStorage:WaitForChild("teamEvent")



local Players = game:GetService('Players')
local LocalPlayer = Players.LocalPlayer

local PlayerGui = LocalPlayer:WaitForChild('PlayerGui')
local teamScreen = LocalPlayer.PlayerGui.ScreenGui.mFrame.ArenaFrame.ArenaOFrame.TeamFrame

local ScreenGui = PlayerGui:WaitForChild('ScreenGui')
local TeamScreen = ScreenGui:WaitForChild('mFrame'):WaitForChild('ArenaFrame'):WaitForChild('ArenaOFrame'):WaitForChild('TeamFrame')
local StatusLabel = ScreenGui:WaitForChild('mFrame'):WaitForChild('ArenaFrame'):WaitForChild('ArenaOFrame'):WaitForChild('TeamFrame'):WaitForChild('StatusLable')
local redFrame = ScreenGui:WaitForChild('mFrame'):WaitForChild('ArenaFrame'):WaitForChild('ArenaOFrame'):WaitForChild('TeamFrame'):WaitForChild('redFrame')
local blueFrame = ScreenGui:WaitForChild('mFrame'):WaitForChild('ArenaFrame'):WaitForChild('ArenaOFrame'):WaitForChild('TeamFrame'):WaitForChild('blueFrame')

teamEvent:FireServer()

Server script:

local PlayerRequirement = 8

local Players = game:GetService('Players')
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local teamEvent = Instance.new("RemoteEvent", ReplicatedStorage)
teamEvent.Name = "teamEvent"
local LocalPlayers = Players.LocalPlayer
StatusLabel = script.Parent.Parent.StarterGui.ScreenGui.mFrame.ArenaFrame.ArenaOFrame.TeamFrame.StatusLable





local function UpdateStatusLabel()
    local NumPlayers = #Players:GetPlayers()
    if NumPlayers < PlayerRequirement then
        StatusLabel.Text = 'Waiting for players (' .. NumPlayers .. '/' .. PlayerRequirement .. ')'
    else
    wait(1)
        StatusLabel.Text = 'Game Start!'
    end
    end


    if StatusLabel.Visible == false then
        Players.PlayerRemoving:Connect(UpdateStatusLabel)

    elseif StatusLabel.Visible == true then
        Players.PlayerAdded:Connect(UpdateStatusLabel)

    end

teamEvent.OnServerEvent:Connect(UpdateStatusLabel)
UpdateStatusLabel() 

If i could get some help with this that would be great!

1 answer

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

Your issue is most likely that you're defining StatusLabel on the client, and trying to use it on the server.

Only clients can see their own GUIs, if you tried to do something like this:

print(game.Players.roseblade578.PlayerGui.ScreenGui)

it would print nil, as the server cannot see inside the PlayerGui folder.

Solution? You could probably just move the UpdateStatusLabel() function and it's :Connect()s to the client script.

Feel free to ask any questions you might have!

0
hmm..that did not seem to work the label did not change it just said Label when I got into the game roseblade578 0 — 4y
0
Did you get any errors? (View -> Output) Professor_Boxtrot 136 — 4y
Ad

Answer this question