I am stuck on something in my code and I can't find whats wrong with it, if someone could tell me what is wrong with my code and how to fix it that would be greatly appreciated. Have a good day.
while true do --This makes sure it keeps going and doesn't die out on us wait(15) --This is how long until the games are started. Recomended that you keep to 5 local m = math.random(1,1) --This randomly selects a game. The seven shows how many games there are local Players = game:GetService("Players") local function onPlayerAdded(player) print("Player: " .. player.Name) end for _, player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end Players.PlayerAdded:Connect(onPlayerAdded) --This checks for players and gets them msg = Instance.new("Message") --This make the annoying messages that appear on you screen msg.Parent = nil --This identifies the game if m == 1 then --don't change unless you know what you are doing msg.Parent = game.Workspace --This makes sure it says and appears in the workspace script.Parent.Text = "Choosing Minigame." --A bunch of messages to tell you that the game is starting which you can change if desired wait(1) script.Parent.Text = "Choosing Minigame.." wait(1) script.Parent.Text = "Choosing Minigame..." wait(1) script.Parent.Text = "A Minigame has been chosen!" wait(3) script.Parent.Text = "The Minigame is..." wait(3) script.Parent.Text = "Obby" --Put the name of the minigame you want it to be called wait(2) script.Parent.Text = "Get to the top before the water gets to the top" --Put the rules of the minigame wait(5) script.Parent.Text = "The game will be starting in:" wait(1) script.Parent.Text = "3" wait(1) script.Parent.Text = "2" wait(1) script.Parent.Text = "1" wait(1) script.Parent.Text = "Begin!" wait(1) player[i].Character:MoveTo(Vector3.new(36.548, 8447.98, -1174.169)) --Replace 206, 31.4, 48.5 with the location of where you want all players to be teleported to at the start of the minigame wait(2) script.Parent.Parent.Visible = false --This removes the annoying messages Don't mess with! game.ServerStorage.ObbyMap:clone().Parent = game.Workspace -- Make a minigame then name it just like this: Minigame1 Once it is named that, put it in the position on the map were you want it to go then put the model in lighting. After you put the model in lighting, you may delete the one in workspace if you wish. wait(10) --How long the game lasts script.Parent.Parent.Visible = true script.Parent.Text = "Winner!" --After the game ends, this shows a message/messages at the end. Edit if you want. wait(3) script.Parent.Parent.Visible = false game.Workspace.ObbyMap:Remove() --Removes the brick so all players die (except spectators) and removes the brick so a new game can start (recommended games aren't over 5 minutes so spectators aren't bored) end
Message is deprecated, use Instance.new("TextLabel") instead if you're trying to get the messages to pop up on each user's local screen. If you're trying to make it appear as an object in the workspace for everyone to see at a static location, then use a BillboardGui/SurfaceGui with a TextLabel inside of it.
Delete the lines about parenting msg and make sure the TextLabel is visible when the text starts. This will create a floating message using a pre-built part/surfacegui/textlabel:
math.randomseed(tick()) --makes your math.random more random --I suggest just pre-building the Part/BillboardGui/TextLabel --You may need to fiddle around with the size and/or text alignment to get it to show correctly local part = game.Workspace.Part --Premade Anchored part that has transparency set to 1 and is 10 studs in the air local surfaceGui = part.SurfaceGui --Premade surfaceGui local showingText = surfaceGui.TextLabel -- Premade TextLabel that has a background Transparency set to 1 and font size set to 50 local Players = game:GetService("Players") --Moved out here, no need to call it multiple times local tickRecord = tick() --Records the time at the very start of the server local counter = 0 local m --The following table uses numbered keys to match the seconds in the game so we can conveniently use a counter to change the text --It uses mixed keys, but that doesn't matter since we aren't iterating through the table --Note that the GameTime is actually 200 seconds, the 35 seconds is for the wait time local minigameText = { [0] = "Choosing Minigame.", [1] = "Choosing Minigame..", [2] = "Choosing Minigame...", [3] = "A Minigame has been chosen!", [6] = "The Minigame is...", [9] = "Obby", [11] = "Get to the top before the water gets to the top", [16] = "The game will be starting in:", [17] = "3", [18] = "2", [19] = "1", [20] = "Begin!", ["GameTime"] = 235, ["Location"] = CFrame.new(36.548, 8447.98, -1174.169) } local function onPlayerAdded(player) print("Player: " .. player.Name) end while true do if tick() - tickRecord >= 15 then --waits 15 seconds if counter == 0 then -- only does this once m = math.random(1,1) game.ServerStorage.ObbyMap:clone().Parent = game.Workspace showingText.Visible = true --make it visible end if m == 1 then -- I just left this here but it'll probably be changed at some point if minigameText[counter] then -- Checks to see if the amount of seconds matches a key in the table showingText.Text = minigameText[counter] --This will change the text according to whatever is inside the minigameText table if counter == 20 then --Begin the game for i, player in pairs (Players:GetChildren()) do --Make sure the character exists and its HumanoidRootPart exists if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then --add an offset of 6 for each character player.Character.HumanoidRootPart.CFrame = minigameText.Location + Vector3.new(0, i * 6, 0) end end wait(.5) -- otherwise it will instantly make the gui invisible, it'll desync the counter by half a second showingText.Visible = false end elseif tick() - tickRecord >= minigameText.GameTime then -- Checks to see if the amount of time passed is equal to 200 seconds --Game ending, this section could use a cleanup but I got tired of coding lol counter = -1 tickRecord = tick() showingText.Visible = true showingText.Text = "Winner!" for i, player in pairs (Players:GetChildren()) do --Teleport Players back --Make sure the character exists and its HumanoidRootPart exists if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then --add an offset of 6 for each character player.Character.HumanoidRootPart.CFrame = CFrame.new(0,0,0) + Vector3.new(0, i * 6, 0) end end wait(3) showingText.Visible = false game.Workspace.ObbyMap:Destroy() --Use destroy instead of remove end end counter = counter + 1 end wait(1) --Delay by ~1 second end Players.PlayerAdded:Connect(onPlayerAdded) --This fires the onPlayerAdded function each time a player is added
I tested it and it works just fine. I think there may have been a problem with your pre-built gui/frame. Usually I don't go through this much trouble to help someone, but eh I was bored lol.