How do StartGame/JoinGame system like Decaying Winter Help

I tried I tried but I couldn’t

You need to answer the three questions in the Scripting Support template
You also need to show the code that you wrote that doesnt work
And you also cant ask people to write whole scripts

3 Likes
  1. I don’t write people to write entire scripts 2) I just asked for help to give me some advice 3) The scripts work, but not the way I wanted because the system crashes on its own. (sorry for bad english)

Well you need to write more than “I tried I tried but I couldn’t”
You need to follow the template
Something like this would be better

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a StartGame/JoinGame system like Decaying Winter
  2. What is the issue? Include screenshots / videos if possible!
    The scripts work, but not the way I wanted because the system crashes on its own
  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    Whatever solutions you have tried
-- The code you have
--server script
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")

local function ensureRemote(name)
	local e = ReplicatedStorage:FindFirstChild(name)
	if not e then
		e = Instance.new("RemoteEvent")
		e.Name = name
		e.Parent = ReplicatedStorage
	end
	return e
end

local REQ = ensureRemote("MatchStartRequest")
local START_C = ensureRemote("StartCountdown")
local PLAYER_SPAWNED = ensureRemote("PlayerSpawned")

local NIGHT_EVENT = ReplicatedStorage:FindFirstChild("StartNightEvent")
local RESPAWN_EVENT = ReplicatedStorage:FindFirstChild("RespawnDeadPlayers")
local CLEAR_AMMO = ReplicatedStorage:FindFirstChild("ClearAmmo")
local NIGHT_VALUE = ReplicatedStorage:FindFirstChild("NightValue")

local countdownTime = 10
local countdownActive = false
local nightDebounce = false

local function getSpawns()
	local folder = Workspace:FindFirstChild("Map")
	if not folder then return {} end
	local list = {}
	for _, p in ipairs(folder:GetChildren()) do
		if p.Name:match("^PlayerSpawn%d*$") then
			table.insert(list, p)
		end
	end
	return list
end

local function teleportPlayer(player)
	local spawns = getSpawns()
	if #spawns == 0 then return end
	local spawn = spawns[math.random(1, #spawns)]
	local char = player.Character or player.CharacterAdded:Wait()
	local hrp = char:WaitForChild("HumanoidRootPart")
	hrp.CFrame = spawn.CFrame
	local stats = player:FindFirstChild("Stats") or Instance.new("Folder", player)
	stats.Name = "Stats"
	local ready = stats:FindFirstChild("IsReady") or Instance.new("BoolValue", stats)
	ready.Name = "IsReady"
	local ingame = stats:FindFirstChild("InGame") or Instance.new("BoolValue", stats)
	ingame.Name = "InGame"
	ready.Value = false
	ingame.Value = true
	PLAYER_SPAWNED:FireClient(player)
end

REQ.OnServerEvent:Connect(function(player)
	local stats = player:FindFirstChild("Stats") or Instance.new("Folder", player)
	stats.Name = "Stats"
	local ready = stats:FindFirstChild("IsReady") or Instance.new("BoolValue", stats)
	ready.Name = "IsReady"
	ready.Value = true

	if countdownActive then return end

	if NIGHT_VALUE and NIGHT_VALUE.Value > 0 then
		RESPAWN_EVENT.Event:Wait()
		for _, p in ipairs(Players:GetPlayers()) do
			local s = p:FindFirstChild("Stats")
			if s and s:FindFirstChild("IsReady") and s.IsReady.Value then
				teleportPlayer(p)
			end
		end
	else
		countdownActive = true
		START_C:FireAllClients(countdownTime, player.UserId)
		task.delay(countdownTime, function()
			for _, p in ipairs(Players:GetPlayers()) do
				local s = p:FindFirstChild("Stats")
				if s and s:FindFirstChild("IsReady") and s.IsReady.Value then
					teleportPlayer(p)
				end
			end
			if NIGHT_EVENT and NIGHT_VALUE and NIGHT_VALUE.Value == 0 and not nightDebounce then
				nightDebounce = true
				NIGHT_EVENT:FireAllClients()
				task.delay(5, function() nightDebounce = false end)
			end
			countdownActive = false
		end)
	end
end)

if NIGHT_VALUE then
	NIGHT_VALUE.Changed:Connect(function()
		if NIGHT_VALUE.Value > 0 and not nightDebounce then
			nightDebounce = true
			task.delay(10, function()
				if CLEAR_AMMO then CLEAR_AMMO:FireAllClients() end
				task.delay(5, function() nightDebounce = false end)
			end)
		end
	end)
end

and local script

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

local player = Players.LocalPlayer
local REQ = ReplicatedStorage:WaitForChild("MatchStartRequest")
local START_C = ReplicatedStorage:WaitForChild("StartCountdown")
local PLAYER_SPAWNED = ReplicatedStorage:WaitForChild("PlayerSpawned")

local gui = player:WaitForChild("PlayerGui")
local menu = gui:WaitForChild("MenuGui")
local spectate = gui:WaitForChild("SpectateGui")
local combat = gui:WaitForChild("CombatGui")
local buffs = gui:WaitForChild("Buffs&Debuffs")

local scripts = player:WaitForChild("PlayerScripts")
local startedCamera = scripts:FindFirstChild("StartedCamera")
local camera = scripts:FindFirstChild("Camera")
local playerCam = scripts:FindFirstChild("PlayerCamera")

local btn = script.Parent
local countdownText = spectate:FindFirstChildWhichIsA("TextLabel")

local countdown = 0
local running = false

local function toggle(obj, state)
	if not obj then return end
	if obj:IsA("ScreenGui") then obj.Enabled = state return end
	if obj:IsA("LocalScript") then obj.Disabled = not state return end
	if obj:IsA("GuiObject") then obj.Visible = state end
end

btn.Activated:Connect(function()
	REQ:FireServer()
	if btn:IsA("TextButton") or btn:IsA("ImageButton") then
		local lbl = btn:FindFirstChildWhichIsA("TextLabel")
		if lbl then lbl.Text = "WAITING..." elseif btn.Text then btn.Text = "WAITING..." end
	end
end)

START_C.OnClientEvent:Connect(function(duration)
	toggle(menu, false)
	toggle(spectate, true)
	toggle(camera, false)
	toggle(startedCamera, true)
	toggle(playerCam, false)
	countdown = duration or 10
	running = true
end)

PLAYER_SPAWNED.OnClientEvent:Connect(function()
	toggle(spectate, false)
	toggle(startedCamera, false)
	toggle(camera, false)
	toggle(playerCam, true)
	toggle(combat, true)
	toggle(buffs, true)
end)

RunService.RenderStepped:Connect(function(dt)
	if running then
		countdown -= dt
		if countdownText then
			countdownText.Text = "Starting in: " .. math.ceil(countdown)
		end
		if countdown <= 0 then
			running = false
			toggle(startedCamera, false)
			toggle(camera, false)
			toggle(playerCam, true)
		end
	end
end)

problem is when 1 player pressing join to game, is working for all players idk why

1 Like