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

player check system doesnt work pls help () its minigame game?


game.Players.PlayerAdded:Connect(function()
	game.ServerStorage.Playernum.Value = game.ServerStorage.Playernum.Value +1 
end)

game.Players.PlayerRemoving:Connect(function()
	game.ServerStorage.Playernum.Value = game.ServerStorage.Playernum.Value -1
end)
game.Players.PlayerAdded:Connect(function()
	if game.ServerStorage.Playernum.Value > 1 then
		script.Parent.Gameintermission.Disabled = false
	else
			script.Parent.Game.Disabled = true
			game.StarterGui.Time.Frame.TextLabel.Text = ("Waiting For Players")
			script.Parent.Gameintermission.Disabled = true
	end
end)

game.Players.PlayerRemoving:Connect(function()
	if game.ServerStorage.Playernum.Value > 1 then
		script.Parent.Gameintermission.Disabled = false
	else
			script.Parent.Game.Disabled = true
			game.StarterGui.Time.Frame.TextLabel.Text = ("Waiting For Players")
			script.Parent.Gameintermission.Disabled = true
	end
end)


--My Script is used to be check check players and run game --note: this is normal script in serverscriptservice

local inttime = game.Workspace.intermission.Value
inttime = 30
for i= 30, 0, -1
do
	inttime = inttime -1
	wait(1)
end
if game.Workspace.intermission == 0 then
	script.Parent.GameSelect.Disabled = false
	script.Disabled = true
endlocal inttime = game.Workspace.intermission.Value
inttime = 30
for i= 30, 0, -1
do
	inttime = inttime -1
	wait(1)
end
if game.Workspace.intermission == 0 then
	script.Parent.GameSelect.Disabled = false
	script.Disabled = true
end
game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = ("leaderstats")
	local cash = Instance.new("IntValue",leaderstats)
	cash.Name = ("Bloxs")
	local level = Instance.new("IntValue",leaderstats)
	level.Name = ("Level")
	
end)

1 answer

Step 1: Create a script to detect ho many players there are

To disable a script when there are 2 or less players in the game do this

local players = game:GetService("Players")

repeat
if #players:GetChildren() < 2 then 
	script.Parent.GameIntermission.Enabled = false
else
	script.Parent.GameIntermission.Enabled = true
end
until #players:GetChildren() > 1

Step 2 create remote event and call it IntermissionEvent

Step 3: You need to fire the remote event to all clients containing how many seconds left

local players = game:GetService("Players")

repeat
if #players:GetChildren() < 2 then 
	script.Parent.GameIntermission.Enabled = false
else
	script.Parent.GameIntermission.Enabled = true
end
until #players:GetChildren() > 1

for i = 30,0,-1 do
	game:GetService("ReplicatedStorage").IntermissionEvent:FireAllClients(i)
end

Step 4: You need to pick up that event in a local script

--//Local Script
--//Note put this script in the TextBox
local textBox = script.Parent

game:GetService("ReplicatedStorage").IntermissionEvent.OnClientEvent:Connect(function(seconds)
	textBox.Text = tostring(seconds.." seconds")
end)

FINAL RESULT

--//SERVER SCRIPT

local players = game:GetService("Players")

repeat
if #players:GetChildren() < 2 then 
	script.Parent.GameIntermission.Enabled = false
else
	script.Parent.GameIntermission.Enabled = true
end
until #players:GetChildren() > 1

for i = 30,0,-1 do
	game:GetService("ReplicatedStorage").IntermissionEvent:FireAllClients(i)
end

and

--//LOCAL SCRIPT
--//Note: put this script in the TextBox
local textBox = script.Parent

game:GetService("ReplicatedStorage").IntermissionEvent.OnClientEvent:Connect(function(seconds)
	textBox.Text = tostring(seconds.." seconds")
end)

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