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

Why wont my script display the winning player??

Asked by 7 years ago

Basically, it's a survival game, and at the end of the level, it supposed to display the winner, but it won't show! The script is in the server script service. Someone please help!!

while true do
local replicatedstorage = game:GetService('ReplicatedStorage')
local status = replicatedstorage.Status
local mapinserverstorage = game:GetService('ServerStorage'):GetChildren()
local chosenmap = mapinserverstorage[math.random(1, #mapinserverstorage)]
local disasterinreplicatedfirst = game:GetService('ReplicatedFirst'):GetChildren()
local chosendisaster = disasterinreplicatedfirst[math.random(1, #disasterinreplicatedfirst)]
local mapstorage = game.Workspace:WaitForChild('mapstorage')
local disaterstorage = game.Workspace:WaitForChild('disaster')
        for i = 3, 0, -1 do
            status.Value = "Game will start in "..i
            wait(1)
        end
        wait(0.5)
        status.Value = 'The map will be '..chosenmap.Name
        wait(2)
        status.Value = 'Get ready'
        wait(0.1)
        status.Value = ''
        chosenmap:Clone().Parent = mapstorage
        for p = 20, 0, -1 do
            status.Value = 'You will be teleported in '..p
            wait(1)
        end
        _G.players = {}
        for i, v in pairs(game.Players:GetPlayers()) do
            if v then
                table.insert(_G.players, v.Name)
            end
        end
        local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
        for _, player in pairs(game.Players:GetPlayers()) do
            if player and #spawns > 0 then
                local torso = player.Character:WaitForChild('Torso')
                local allspawns = math.random(1, #spawns)
                local randomspawn = spawns[allspawns]
                if randomspawn and torso then
                    table.remove(spawns, allspawns)
                    torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0, 2, 0))
                wait(0.1)
            end
        end
    end
    wait(2)
    status.Value = 'Prepare...'
    wait(0.9)
    status.Value = 'The world will end by...'
    wait(0.3)
    status.Value = chosendisaster.Name
    wait(0.3)
    chosendisaster:Clone().Parent = disaterstorage
        for p = 5, 0, -1 do
            wait(1)
            status.Value = p.." Seconds Left To Survive!"
            end
            if status.Value == '0 Seconds Left To Survive!' then
            mapstorage:ClearAllChildren()
            disaterstorage:ClearAllChildren()
            status.Value = 'Game over!!'
            wait(2)
                    if #_G.player == 1 then
                    for i, v in pairs(_G.players) do
                        if v ~= nil then
                        status.Value = v..' has survived and get 100 points!'
                        break

                    end
                    end
                    break
        end
        end

end
0
why are you using the global table. is it used in multiple scripts connor12260311 383 — 7y
0
i was using a alvinblox tutorial supercoolboy8804 114 — 7y
0
You don't require the _G global thingy anymore; you can use ModuleScripts instead, which have more advantages, as for example, it can be used by both server-sides & client-sides. TheeDeathCaster 2368 — 7y
0
uhh im kinda still new to modules, wold you mind showing me the script i would use? supercoolboy8804 114 — 7y
0
Here's a document on ModuleScripts: http://wiki.roblox.com/index.php?title=API:Class/ModuleScript TheeDeathCaster 2368 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

On line 61 you typed #_G.player but that needs to be #_G.players If this helped be sure to accept this answer

Ad

Answer this question