what is wrong with it. I put it in starterpack so it runs automatically. nothing happens.
game.Players.PlayerAdded:connect(function(player) wait() while true do if game.Workspace.PlayerCount.Players.Value <= 2 then game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = "Waiting for at least FIVE players to join..", Color = Color3.new(100, 100, 0), Font = Enum.Font.SourceSansLight, FontSize = Enum.FontSize.Size18, print("made it here lol") }) wait(10) end wait() if game.Workspace.PlayerCount.Players.Value >= 2 and game.Workspace.game.CanCollide == true then game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = "Welcome to the annual HUNGER GAMES", Color = Color3.new(100, 0, 0), Font = Enum.Font.SourceSansLight, FontSize = Enum.FontSize.Size18, }) local a = true if a == true then player.TeamColor = BrickColor.new("Forest green") wait(10) game.Workspace.game.CanCollide = false game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = "If you don't know how to play, read the description!", Color = Color3.new(0, 100, 0), Font = Enum.Font.SourceSansLight, FontSize = Enum.FontSize.Size18, }) a = false local b = true wait(10) game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = "Selecting random arena...", Color = Color3.new(100, 100, 530), Font = Enum.Font.SourceSansLight, FontSize = Enum.FontSize.Size18, }) elseif 1 b == true then wait(5) game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = "Arena selected. Prepare to enter the game. May the odds be ever in your favor.", Color = Color3.new(322, 100, 0), Font = Enum.Font.SourceSansLight, FontSize = Enum.FontSize.Size18, }) b = false local c = true elseif c == true then wait(20) local Pos = player.Character:GetPrimaryPartCFrame() player:LoadCharacter() player.Character:SetPrimaryPartCFrame(Pos) if player.Character:FindFirstChild("ForceField") then player.Character["ForceField"]:Destroy() wait(1) game.ReplicatedStorage.Remotes.tp:FireServer() c = false end end end end end)
First of all, you should always indent your code properly to make it more readable.
Server Scripts
do not work in StarterPlayer
. They only work in either Workspace
, or ServerScriptService
. Consider either moving it to those locations or changing the script into Local Script
.
You shouldn't be using while true do
loop for this. You should make a Server Script
. that invokes the Local Script
. And the Local Script
handles the major framework and/or communicates with Server Script
if necessary.
For example
-- [Declaration Section] --\\ Services local ReplicatedStorage = game:GetService("ReplicatedStorage"); local Players = game:GetService("Players"); --\\ Remote Event local OnPlayerEvent = ReplicatedStorage:WaitForChild("OnPlayerEvent"); local RequirementEvent = ReplicatedStorage:WaitForChild("RequirementEvent"); --\\ IntValue Adding local AmountOfPlayers = script.AmountOfPlayers; --\\ Starting Numbers of Players local MIN = 5; -- [Processing Section] local function On_Player_Added () AmountOfPlayers.Value = AmountOfPlayers.Value + 1; print(AmountOfPlayers.Value); if AmountOfPlayers.Value >= MIN then print(AmountOfPlayers.Value .. ": Invoking!"); RequirementEvent:FireAllClients(true); else print(AmountOfPlayers.Value .. ": Not Enough!"); RequirementEvent:FireAllClients(false); end; end; local function On_Player_Leaved () AmountOfPlayers.Value = AmountOfPlayers.Value - 1; print(AmountOfPlayers.Value); end; -- [Connecting Section] Players.ChildAdded:Connect(On_Player_Added); Players.ChildRemoved:Connect(On_Player_Leaved);
-- [Declaration Section] --\\ Game Services local ReplicatedStorage = game:GetService("ReplicatedStorage"); local Player = game:GetService("Players").LocalPlayer; local Character = Player.Character or Player.CharacterAdded:Wait(); --\\ Remote Event Location local RequirementEvent = ReplicatedStorage:WaitForChild("RequirementEvent"); -- [Processing Section] local function On_Player_Added (Value) if Value == true then print("Enough Players: Starting Game"); -- Do Stuff else print("Not Enough Players"); end end; -- [Connecting Section] RequirementEvent.OnClientEvent:Connect(On_Player_Added);
Of course, there are numerous ways to do this, and this is just one of the ways. With the above code, you have to make sure that the Remote Event
does not fire in the middle of the game. This can simply be achieved by using Boolean
values.
Hope this gives you a starting idea on how to manage scripts. You should also always be utilizing Module Scripts
.