Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my script only affect the second joined person GUI? (SOLVED)

Self-explanatory question. The script only affect for the second joined user. The script is:

x = 20
local ScreenGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
local allplayers = game.Workspace.Values.TotalPlayers.Value

function intermission()
	repeat wait(1)
	ScreenGui.TextLabel.Text = "Game starting in ".. x .. " seconds."
	x = x - 1
	until x == -1
	if allplayers > 1 then
		ScreenGui.TextLabel.Text = "Game starting!"
	end
end

function checkplayer()
	if allplayers > 1 then
		intermission()
	end
	if allplayers < 2 then
		print("Not enough players! ".. 2 - allplayers .." more player are needed")
		ScreenGui.TextLabel.Text = "Not enough players! ".. 2 - allplayers .." more player are needed to start the game."
		repeat wait(1) until allplayers > 1
		intermission()
	end
end


checkplayer()

2 comments

0

If you have any questions about my script or you want some more details, question in comments

1

Alr testin it right now

2 answers

Alright. I have no idea what the problem is but here is the script that worked for me.

x = 20
ScreenGui = script.Parent
allplayers = #game.Players:GetPlayers()
function intermission()
	for i = x,0,-1 do
		wait(1)
		ScreenGui.TextLabel.Text = "Game starting in " .. i .. " second(s)!"
	end
	if allplayers == 1 then
		ScreenGui.TextLabel.Text = "Game starting!"
		print('Worked')
	end
end
function checkplayer()
	if allplayers > 2 then
		intermission()
	end
	if allplayers < 2 then
		print("Not enough players! ".. 2 - allplayers .." more player are needed")
		ScreenGui.TextLabel.Text = "Not enough players! ".. 2 - allplayers .." more player are needed to start the game."
		repeat wait(1) until allplayers > 2
		intermission()
	end
end
checkplayer()

1 comment

0

Uhmm... sorry 'bout that but I knew the answer. Thanks for answering though. There is a better solution by the other guy, but he didn't post answer up here. Sorry but I can't make you as the correct answer. But I still upvoted! Thanks for helping though. <3

Alright guys. I got the answer.

Basically, the allplayers value didn't update. So thats why the first person joined still stuck in the value 1 while the second one is stuck in the 2 value variable.

So I made a simple script that update the allplayers value for everyone when someone joined / left.

The script:

Players.PlayerAdded:Connect(function(Player)
	AmountOfPlayer = AmountOfPlayer + 1
	print("A person has joined the game! Total player in server currently is ".. AmountOfPlayer.. ".")
	value.Value = AmountOfPlayer
	allplayers = game.Workspace.Values.TotalPlayers.Value
end)

Players.PlayerRemoving:Connect(function(Player)
	AmountOfPlayer = AmountOfPlayer - 1
	print("A person has left the game! Total player in server currently is ".. AmountOfPlayer.. ".")
	value.Value = AmountOfPlayer
	allplayers = game.Workspace.Values.TotalPlayers.Value
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.