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

My script only unpacks 1 item from a table?

Here is the area effected:

status.Value = "Round over!"
	local winners = {}
	for i, v in pairs(plrs) do
		if v:FindFirstChild("Tag") then
			v:FindFirstChild("Tag"):Destroy()
			v:WaitForChild("leaderstats"):WaitForChild("Survivals").Value = v:WaitForChild("leaderstats"):WaitForChild("Survivals").Value + 1
			v:WaitForChild("leaderstats"):WaitForChild("Points").Value = v:WaitForChild("leaderstats"):WaitForChild("Points").Value + 3
			local t = v:WaitForChild("PlayerGui"):WaitForChild("Status"):WaitForChild("Winners")
			table.insert(winners,v.Name..", ")
		end
	end
	workspace.Terrain:Clear()
	workspace.LavaPart.Size = workspace.LavaPart.S.Value
	workspace.LavaPart.Position = workspace.LavaPart.P.Value
	for i, v in pairs(game.Players:GetPlayers()) do
		local t = v:WaitForChild("PlayerGui"):WaitForChild("Status"):WaitForChild("Winners")
		v.Character:WaitForChild("Humanoid").Health = v.Character:WaitForChild("Humanoid").MaxHealth
		t.Visible = true
		if #winners >= 1 then
			t.Text = tostring(table.unpack(winners,1,#winners)).." survived!"
		else
			t.Text = "Nobody survived!"
		end
		chosen:Destroy()
		wait(5)
		t.Visible = false
	end

It should make all the survivors name appear on the TextLabel but it only puts 1.

2 comments

0

Can you make leaderstats and Survivals and Points variables so that you don't need to type out WaitForChild everytime?

0

I literally only wrote down each one time. :/

1 answer

✓ Accepted answer

The reason why it only does one is because tostring only accepts 1 parameter, and unpack will return those values as each a different parameter

I put function together what does what you need, but there is probably a function out there who does it already

local function addTogether(...)
	local sumText = ""
	for _,k in pairs({...}) do
		sumText ..= k --do tostring(k) if the values arent a string
	end
	return sumText
end

so now u do this instead

 t.Text =addTogether(table.unpack(winners)).." survived!" 

and it will work

u can also modify this function to add spaces or commas between the winners names

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