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

Table problem, it is only inserting one player?

Asked by 7 years ago
_G.Snipers = {z}
local status = workspace.Values.Status
function begin()

workspace.Values.Snipers.Value = true
workspace.Values.Intermission.Value = false
    local plr = game.Players:GetPlayers()
    for i,v in pairs (plr)do 
        table.insert(_G.Snipers,v.Name) -- Only inserts one player into the table??? WHYY
        print(v.Name..' is _G.Snipers')
        local char = v.Character
        local human = char:WaitForChild('Humanoid') 
        if char and human then  
            workspace.Values.Status.Value = 'The next gamemode is Snipers!'
            wait(5)
            char:WaitForChild'Torso'.CFrame = CFrame.new(workspace.Spawn.Position) -- Teleport to arena 
            status.Value = 'Based off the original "Quick Scoping", this game mode everyone faces off with a sniper to be the last one standing '
            wait(5) 
            status.Value = 'Giving every player their sniper...'
            game:GetService('ReplicatedStorage').Tools.Sniper:Clone().Parent = v:WaitForChild('Backpack')
        end
        wait(3)
        for i = 100,0,-1 do
            wait(1) 
            status.Value = 'Kill every player and be the last one standing to win!'
if #_G.Snipers == 1 then
for i,winner in pairs (_G.Snipers) do
    if game.Players:FindFirstChild(winner) then --Finding the winner
        if winner ~= nil then
            status.Value = winner..' is the winner of the round and has recieved 100 CREDZ'
        game:GetService('ReplicatedStorage').Bank:WaitForChild(winner).Value = game:GetService('ReplicatedStorage').Bank:WaitForChild(winner).Value + 100
        workspace:FindFirstChild(winner).Humanoid.Health = 0
        _G.Snipers = {} -- Reset Table
        wait(3)
        workspace.Values.Round.Value = false
        workspace.Values.Intermission.Value =true
        workspace.Values.Snipers.Value = false      
        script:remove()
        break
        end
        end
end
end
break
        end
    end
end
begin()

I named where it errored but for some reason everytime it runs, it adds one player to the table, does anyone know what i did wrong?

0
ignore the z i accidentally typed it. sentry3 6 — 7y
0
Lines 26-29 are the logic causing you problem. Learning to properly indent can help prevent these problems. You insert a player, then check if there is only one player in the table (true), then try to find the player and remove the script so no other player is added to the table. Also, use :Destroy() instead of :remove(). GoldenPhysics 474 — 7y
0
if you dont mind my asking.. whats the difference between those two? sentry3 6 — 7y
0
also, line 7-10 is also a problem because it doesnt load all the players into the table sentry3 6 — 7y
View all comments (9 more)
0
Remove is deprecated and no longer supported. No that part works, you're just breaking the loop and deleting the script, preventing the loop that adds your players from continuing. Can you talk in the site or discord chat? GoldenPhysics 474 — 7y
0
i sent you a fr on the site so that i can chat with you sentry3 6 — 7y
0
What site? Roblox? GoldenPhysics 474 — 7y
0
yes sir sentry3 6 — 7y
0
That's too slow, and it's not easy to show code with that. Discord then? GoldenPhysics 474 — 7y
0
yea, how will i chat with you on that? sentry3 6 — 7y
0
im not allowed to chat it sais sentry3 6 — 7y
0
Do you see a "Welcome" channel? GoldenPhysics 474 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Function Called before More Players have joined, add

repeat wait() until game.Players.NumPlayers>=MinPlayers 

At the start of the Begin function and call Begin() again at the end to loop it.

Ad

Answer this question