I am trying to make the character load, than afterwards spawn to the specific area.
It works without loadcharacter but when i add it, it wont run the CFrame vector.
for _, Player in pairs(game.Players:GetPlayers()) do
local character = Player.Character
coroutine.wrap(function()
Player:LoadCharacter()
wait(1)
character:FindFirstChild("Torso").CFrame = table.remove(AvailableSpawnPoints, math.random(#AvailableSpawnPoints)).CFrame + Vector3.new(0,10,0)
end)()
end
I don’t think you can set a position from removing a table item. Pretty sure you need to first grab the item in the table and send the player there. After that you can remove it from the table.
Your table.remove doesn’t even work anyway. Read the error from the output.
You should go about this the following way:
for _, Player in pairs(game.Players:GetPlayers()) do
local character = Player.Character
coroutine.wrap(function()
local selected = math.random(1,#AvailableSpawnPoints)
character:WaitForChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[selected].CFrame + Vector3.new(0,10,0)
table.remove(AvailableSpawnPoints,selected)
end)
end
Do note, I’m not aware if this will even work with your table. To my knowledge, the code I have modified should work if your table is set up correctly. It’s up to you to look at the code I’ve changed and add it in so it will work. The DevForum isn’t here to do all the scripts for you.
It’s also dependant upon how your table is set up. The CFrame changing may not work if your table is set up differently than what you tried doing.
Edit: This response might not be what you’re looking for. You need to specify the character after your load character like @ChasingSpace said. If that works, please mark his response as correct.
I never thought about this, and that is genius. TIL!
As for why it doesn’t move, you’re assigning character to the player’s old character, and when you run LoadCharacter, they have a new character. Try using Player.Character after the wait, and remove the previous character variable.
It works without loadcharacter but when i add it, it wont run the CFrame vector.
The problem isn’t the usage of table.remove here, otherwise it wouldn’t work with LoadCharacter not being there. You also updated your code to remove the LoadCharacter call, which they seem to have a need for since they’ve tried it without it.
Try replacing character with Player.Character on the CFrame line. It looks like when you call LoadCharacter the old character model is unparented and replaced, so your variable no longer contains the correct model anymore.