Here's my attempt, please tell me what is wrong. I am trying to make a roblox version of Escape The Night, but for it to begin in the pre-alpha stages, at least 2 players need to be in the game
game.local Players = game:GetService("Players") local P = game.workspace.Play Players.PlayerAdded:Connect(function(player) print(player.Name .. " joined the game!") P.Value = P.Value + 1 end) Players.PlayerRemoving:Connect(function(player) print(player.Name .. " left the game!") P.Value = P.Value - 1 end) local v = game.Workspace.Play.Value v:GetPropertyChangedSignal("Value"):Connect(function() if P.Value >= 1 then game.Workspace.Beep:Play() game.StarterGui.ScreenGui.TextLabel.Text = "The party is about to start..." wait(2) game.Workspace.Beep:Play() game.StarterGui.ScreenGui.TextLabel.Text = "Don't scream too loud, you'll wake him up." wait(2) game.Workspace.Beep:Play() game.StarterGui.ScreenGui.TextLabel.Text = "But most importantly, have FUN!" print("Success") end end)
What do I mean by FE? FE stands for Filtering Enabled, the type of client-server system Roblox has used on all games since 2018. It's a game industry standard, meant to help minimize exploits. Essentially, the system is like this:
Any change on the client stays on the client, it doesn't change on the server. Any change on the server, though, will make the change on all clients, too. The server cannot touch anything ONLY on the client, however.
As a result, any scripting revolving the client cannot be scripted from a regular script. Assuming this is in ServerScriptService or Workspace (I personally prefer the former), it's not working because you're trying to change the UI on the server. UI is part of the client, so the server doesn't have "access" to it. Therefore, using StarterGui
won't do anything on the server. Not to mention that StarterGui wouldn't be how you change the GUI. In order to change UI, you need to use a RemoteEvent
. This fires an event down to the client, which can then receive it and change the UI if needed.
This is what'd happen when scripting while respecting FE:
--SERVER SCRIPT --Create a remote event and place it in replicatedstorage game.local Players = game:GetService("Players") local P = game.Workspace.Play --Capitalization is key! Players.PlayerAdded:Connect(function(player) print(player.Name .. " joined the game!") P.Value = P.Value + 1 end) Players.PlayerRemoving:Connect(function(player) print(player.Name .. " left the game!") P.Value = P.Value - 1 end) P:GetPropertyChangedSignal("Value"):Connect(function() --No need to change to V, as it's the same thing! if P.Value > 1 then --It'll run at 2 like that game.ReplicatedStorage:FireAllClients() -- Fires a message to all clients print("Success") end end)
You'd need a local script, too now! This is assuming if it's in starter gui:
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui") -- This is the actual UI you want to change, Starter GUI replicates itself into the player game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function() --How to detect event on client game.Workspace.Beep:Play() PlayerGui.ScreenGui.TextLabel.Text = "The party is about to start..." wait(2) game.Workspace.Beep:Play() PlayerGui.ScreenGui.TextLabel.Text = "Don't scream too loud, you'll wake him up." wait(2) game.Workspace.Beep:Play() PlayerGui.ScreenGui.TextLabel.Text = "But most importantly, have FUN!" end)
If you need more reference: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events https://developer.roblox.com/en-us/api-reference/property/Workspace/FilteringEnabled
In line 12 you made it so if there is greater or "equal" to 1 player. Take out the "=" if that's not it please message me back.
Here's a script i'm using for my game:
local playernumber game.Players.PlayerAdded:Connect(function(p) if playernumber == nil then playernumber = 1 else playernumber = playernumber +1 end end) game.Players.PlayerRemoving:Connect(function(p) playernumber = playernumber -1 end) function playercount() for number,plrs in pairs(game.Players:GetPlayers()) do if number == nil or plrs == nil then return 0 else return number end end end while wait(1 + math.random()) do if playercount() >=2 then print"ok game starting" break else print"you need 2 players to start" end end
if it works accept , thank you.