Hi.
I am new to scripting, but I wanted to try to make a roblox game with help of ChatGPT (I somewhat know how to script but Im not good at it). When I finished writing a script, it gives no error messages, but doesnt work. Can you help me find what’s wrong in the script? PS. It’s not a local script but a normal script and it is in ServerScriptStorage
This script for now was supposed to start the game after there are more than 1 player on the server. I posted photo of how the game outside looks. When game starts, the script was supposed to print random color and then all blocks this color would slowly fall and after 4 seconds come back. At the start of game the script was supposed to count the players and when a player die remove him from game. If there was only 1 player left on the map the game would end. I dont know what is wrong with the code, because i am just starting scripting so i need some help with analyzing this script.
local Players = game:GetService("Players")
local function PlayerAdded(plr)
end
Players.PlayerAdded:Connect(PlayerAdded)
for _,v in pairs(Players:GetPlayers()) do
PlayerAdded(v)
end
local playersOnBoard = {}
local function checkIfPlayerDied()
for i, player in ipairs(playersOnBoard) do
if player.Health <= 0 then
return player
end
end
return nil
end
local function initializePlayersOnBoard()
local allPlayers = game.Players:GetPlayers()
for _, player in ipairs(allPlayers) do
table.insert(playersOnBoard, player)
end
end
local function removePlayerFromBoard(player)
for i, p in ipairs(playersOnBoard) do
if p == player then
table.remove(playersOnBoard, i)
break
end
end
local playerDied = checkIfPlayerDied()
if playerDied then
print(playerDied.Name .. " has died!")
removePlayerFromBoard(playerDied)
end
local blocks = {
Red = workspace.Colors.Red,
Blue = workspace.Colors.Blue,
Green = workspace.Colors.Green,
Yellow = workspace.Colors.Yellow,
Purple = workspace.Colors.Purple,
Brown = workspace.Colors.Brown
}
local function generateRandomColor()
return math.random(1, 6)
end
local function displayColorMessage(colorNumber)
local colors = {"Red", "Blue", "Green", "Yellow", "Purple", "Brown"}
print(colors[colorNumber] .. " disappears!")
end
local function removeBlock(block)
block.Transparency = 1
block.CanCollide = false
end
local function blockDisappear()
local colorNumber = generateRandomColor()
local colorName = displayColorMessage(colorNumber)
if blocks[colorName] then
local block = blocks[colorName]
block.Position = block.Position - Vector3.new(0, 10, 0)
wait(1)
for transparency = 0, 1, 0.1 do
block.Transparency = transparency
wait(0.1)
end
removeBlock(block)
wait(4)
block.Position = block.Position + Vector3.new(0, 10, 0)
block.Transparency = 0
block.CanCollide = true
end
end
local players = {}
local round = 1
local gameInProgress = false
local function checkRemainingPlayers()
local allPlayers = game.Players:GetPlayers()
if #allPlayers >= 2 then
print("Game starts!")
gameInProgress = true
end
for _, player in ipairs(allPlayers) do
table.insert(players, player.Name)
end
while true do
if gameInProgress == false then
print("Waiting for players...")
else
local colorNumber = generateRandomColor()
displayColorMessage(colorNumber)
blockDisappear()
if round == 6 then
print("Game just got harder!")
end
if (playersOnBoard == 1) then
print("Game over, GG!")
break
end
round = round + 1
end
end
end
end