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

Tables and CFraming issues, any help?

Basically, I'm trying to make a spawning system using tables. Every time a player is spawned, the spawn they are going to be spawned in will be removed from the table, so no other player will be sharing their spawn. Afterwards, once everyone is spawned, the game continues. However, it doesn't remove it from the table and instead still makes people share spawns.

I tried making a for loop to find if any of the selected spawns equaled to the index but that didn't work. I also tried following tutorials, but that didn't work. I've been trying to find a fix for a while now, but I eventually gave up. Any help fixing would be greatly appreciated.

for i = 1,PlayerCount do 
		if not PlayerTable[i].AFK.Value and PlayerTable[i].Character and PlayerTable[i].Character.Humanoid.Health > 0 then
			local Spawns = workspace.CurrentMap:FindFirstChild(MapChosen).Spawns:GetChildren()
			local Character = PlayerTable[i].Character
			Character.HumanoidRootPart.CFrame = Spawns[1].CFrame + Vector3.new(0,2,0)
			table.remove(Spawns,1)
		end
	end

1 answer

✓ Accepted answer
local Spawns = workspace.CurrentMap:FindFirstChild(MapChosen).Spawns:GetChildren()

for i = 1,PlayerCount do
	local player = PlayerTable[i] -- store the player in a variable
	local char = player.Character -- and their character
	if not player.AFK.Value and char and char.Humanoid.Health > 0 then
		-- "i" is going to increase, so no point in *removing* any spawns
		-- since we can easily skip over them
		char.HumanoidRootPart.CFrame = Spawns[i].CFrame + Vector3.new(0, 2, 0)
	end
end

NOTE: this will error if there are more players than spawns

1 comment

0

Thanks man!

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