Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my Round System never working?

Asked by 9 years ago

I looked at so many tutorials but they only work for 'Printing' or 'Hint's'. Also, I tried to change the hint's to text, but it won't work.

I've tried many things to fix this problem but none of them are doing the trick, so I was wondering if someone could help. Thanks!

Errors: Text won't change. Map's won't load. It will not teleport you to the map.

Code:

local playerNotifications = game.StarterGui.ScreenGui.Frame.TextLabel

function waitForPlayers()
    if game.Players.NumPlayers < 1 then
        playerNotifications.Text = "Waiting for players!"
    end
end

function intermissionTimer()
    if game.Players.NumPlayers > 1 then
        for countDown = 10, 1, -1 do
        playerNotifications.Text = "Intermission: " ..countDown
    end
end

function displayGamemode()
    - Couldn't find code for this.
end

function mapSelection()
    local mapList = game.ReplicatedStorage.Maps:GetChildren()
    local randomMap = math.random(1, #mapList)
    playerNotifications.Text = "Choosing the map!"
    wait(4)
    local mapChosen = mapList[randomMap]
    playerNotifications.Text = "The map is: " ..mapChosen.Name
    local mapClone = mapChosen:Clone()
    mapClone.Parent = game.Workspace
end

function teleportAllPlayers()
    local target = CFrame.new(mapClone.Spawns.Position)
    for i, player in ipairs(game.Players:GetChildren()) do
        player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
        player.Playing.Value = 1
    end
end

function startingTimer()
    for countDown = 3, 1, -1 do
        playerNotifications.Text = "Game begins in: " ..countDown
    end
end

function roundTimer()
    for countDown = 20, 1, -1 do
        playerNotifications.Text = "Time left: " ..countDown
    end
end

function roundEnded()
    - Couldn't find code for this.
end

function teleportAlivePlayers()
    local target = CFrame.new(workspace.TeleportTarget.Position)
    for i, player in ipairs(game.Players:GetChildren()) do
        player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
        player.Playing.Value = 0
    end
end

function mapDestroy()
    - Couldn't find code for this.
end

function showResults()
    - Couldn't find code for this.
end

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            player.Playing.Value = 0
        end)
    end)

    local playing = Instance.new("IntValue", player)
    playing.Value = 0
    playing.Name = "Playing"
end)

while(true) do
      waitForPlayers()
      wait(0)
      intermissionTimer()
      wait(0)
      displayGamemode()
      wait(5)
      mapSelection()
      wait(5)
      teleportAllPlayers()
      wait(0)
      startingTimer()
      wait(0)
      roundTimer()
      wait(0)
      roundEnded()
      wait(0)
      teleportAlivePlayers()
      wait(0)
      mapDestroy()
      wait(0)
      showResults() 
   end
end
0
You have too many ends at the end. Move the end from 105 to line 12, since the script is thinking you're trying to end the function, not the loop all the way at line 11 M39a9am3R 3210 — 9y
0
You need 2 hyphens or it will error all the code below. https://gyazo.com/45afd362dc675514eccee844b46855b9 Azmidium 388 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Problem #1: Notifications

StarterGui is basically where the guis get cloned from, it doesn't change everyone's guis. So, instead, you make a function, right at the start that you call whenever you want to change text:

function notification(text)
    for _,v in pairs (game.Players:GetChildren())
        local find = v.PlayerGui:FindFirstChild("ScreenGui")
        if find then
            find.Frame.TextLabel.Text = text
        end
    end
end

-- to call it: notification("your text here")

Problem #2: Map

It should work, I see no problems. It is most likely something before the map function has errored.

Problem #3: Teleporting

The problem is that MapChosen is a local inside the MapSelection function, which means it doesn't exist inside TeleportPlayers().

To fix this, I would recommend you just create a local right at the start of the script, on Line 2 or something, called "CurrentMap". When it chooses the map, it sets CurrentMap to MapChosen, so inside the MapSelection function:

CurrentMap = MapChosen

This will mean you can get the current map in the entire script.

Also, here are some things to fix:

1. Make WaitForPlayers() a while loop, so:

function WaitForPlayers()
    while game.Players.NumPlayers < 2 do
        notification("You need 1 more player to start the game.")
    end
end

2.IntermissionTime() needs an end under the for loop.

Hope I helped :)

Ad

Answer this question