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

How to add players to table? (Easy)

I have table

players {

}

and I have player that touched the block


Players = game:GetService("Players")

block:Tocuched:Connect(function(part)

	character = part.Parent

	player = Players:GetPlayerFromCharacter(character)

end)

So, when player touched the block I need add this player to this table.

I want teleport that players and for that I need add them into the table.

1 comment

0

use table.insert()

1 answer

✓ Accepted answer

Dont forget local.

local Players = game:GetService('Players')
local Players_Table = {}

local block = script.Parent

block.Touched:Connect(function(hit)
	local Player = Players:GetPlayerFromCharacter(hit.Parent) -- This isn't the Character of the Player but the instance that you can see on "Players" in the explorer.
	if Player and not table.find(Players_Table, Player) then
		print(table.find(Players_Table, Player))
		table.insert(Players_Table, Player) -- Add the player in the table
		if Player.Character then
			Player.Character:MoveTo(Vector3.new(0, 10, 0))
			delay(1, function()
				table.remove(Players_Table, table.find(Players_Table, Player)) -- Remove the player of  the table after 1 seconde
			end)
		end
	end
end)

2 comments

0

Thanks you. You just explain me how to delete player from table and how to add.

0

Thanks you. You just explain me how to delete player from table and how to add.

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