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

Script isn't working in online mode?

Asked by 9 years ago

Everything works in Play Solo and the gui shows up fine, but when I tried it in online mode, nothing worked. Here's the code:

--Made by Aceta

players = game.Players:GetPlayers()
local timeleft = Workspace:findFirstChild('time')
local piece = Workspace.teleportationpart
local map = Workspace.Map
current = {}

function removeTime()
        for i = 120, 0, -1 do
                wait(1)
                timeleft.Value = i
        end
end

function gameStart()
        for i, v in pairs(players) do
                local stats = v.PlayerGui.fullGui.everything.gamePlay.informer
                stats.Text = 'New round beginning!'
                stats.FontSize = 'Size24'
                timeleft.Value = 120
                wait(1)
                stats.Text = ''
        end
        teleportPlayers()
        countdown()
        removeTime()
end

function teleportPlayers()
        for i, v in pairs(players) do
                if v.play.Value == true then
                        v.Character.Torso.CFrame = CFrame.new(piece.Position+Vector3.new(
                                math.random(1,10),
                                math.random(2,6),
                        math.random(1,10)))
                        table.insert(current, v.Name)
                end
        end
end

function countdown()
        for i, v in pairs(current) do
                local stats = game.Players:FindFirstChild(v).PlayerGui.fullGui.everything.gamePlay.informer
                stats.Text = '3'
                wait(1)
                stats.Text = '2'
                wait(1)
                stats.Text = '1'
                wait(1)
                stats.Text = 'Begin!'
                stats.FontSize = 'Size48'
                wait(2)
                stats.Text = ''
                wait(1)
                stats.Text = 'Objective: Find a weapon. '
                stats.FontSize = 'Size36'
        end
end

function endGame()
        for i,v in pairs(current) do
                current[i] = nil
        end
end

function waitSome()
        for i, v in pairs(players) do
                local stats = v.PlayerGui.fullGui.everything.gamePlay.informer
                stats.FontSize = 'Size24'
                stats.Text = "Let's take a quick break. Use this time to buy stuff in the shop!"
                wait(30)
                stats.Text = ''
        end
end

while wait() do
        gameStart()
        endGame()
        wait(1)
        waitSome()
end
0
Are you getting any output? While it's ugly, I can't see any part of this script that could be problematic. adark 5487 — 9y
0
No output at all. RedneckBane 100 — 9y

1 answer

Log in to vote
1
Answered by
Defaultio 160
9 years ago

I think your problem is that you're only calling game.Players:GetPlayers() once, at the beginning of your script. This is fine in solo because you only have one player, and that player exists immediately on the start of the game, so he or she gets in that list. However, in a server, the server starts and code runs before any players get into the game, so your players list is empty and stays empty. It's running the code fine, for all 0 players it thinks are in the game. Just refresh that list through every iteration of the loop!

Ad

Answer this question