Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Table problem, it is only inserting one player?

_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?

13 comments

0

ignore the z i accidentally typed it.

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().

0

if you dont mind my asking.. whats the difference between those two?

0

also, line 7-10 is also a problem because it doesnt load all the players into the table

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?

0

i sent you a fr on the site so that i can chat with you

0

What site? Roblox?

0

yes sir

0

That's too slow, and it's not easy to show code with that. Discord then?

0

yea, how will i chat with you on that?

0

im not allowed to chat it sais

0

Do you see a "Welcome" channel?

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.