for index, value in pairs(_G.Team1) do
value.CharacterAdded:Connect(function(character)
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
for index2, value2 in pairs(attackerSelectedSpawnLocation) do
if table.find(value2, value) then
humanoidRootPart.Anchored = true
humanoidRootPart.CFrame = workspace[selectedMapStringValue.Value].AttackerSpawnLocations[index2].CFrame
repeat task.wait() until humanoidRootPart.CFrame == workspace[selectedMapStringValue.Value].AttackerSpawnLocations[index2].CFrame
humanoidRootPart.Anchored = false
table.insert(loadedTable, value)
end
end
value:LoadCharacter()
end
The Player will not teleport to the Part when the Character and HumanoidRootPart is added and i change the CFrame to the Part. But when i add a wait(1) over humanoidRootPart.CFrame = workspace[selectedMapStringValue.Value].AttackerSpawnLocations[index2].CFrame it will teleport. Why?
Why are you waiting for it to ==? You already set it, also you should NOT anchor the HumanoidRootPart.
Replace your if statement with this;
if table.find(value2, value) then
humanoidRootPart.CFrame = workspace[selectedMapStringValue.Value].AttackerSpawnLocations[index2].CFrame
table.insert(loadedTable, value)
end
Edit : Ok, I cleaned up your code a little and I’m pretty sure you are missing an end.
for index, value in pairs(_G.Team1) do
value.CharacterAdded:Connect(function(character)
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
for index2, value2 in pairs(attackerSelectedSpawnLocation) do
if table.find(value2, value) then
humanoidRootPart.CFrame = workspace[selectedMapStringValue.Value].AttackerSpawnLocations[index2].CFrame
table.insert(loadedTable, value)
end
end
end)
value:LoadCharacter()
end
Hey, thanks for your answer, im waiting because it has delay before it will teleported to the other CFrame, im anchoring the HumanoidRootpart and unanchoring after the Humanoid is teleported to the parts CFrame, if i would not anchor it, sometimes it would not fire. And im not missing an end, i just accidently dont copy pasted another end.
The Problem is the CFrame will not set after the Player is spawned also not with your Code, just when i add task.wait(1) but why?
I don’t know why it doesn’t work without task.wait(), but you can try this.
for index, value in pairs(_G.Team1) do
value.CharacterAdded:Connect(function(character)
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
for index2, value2 in pairs(attackerSelectedSpawnLocation) do
if table.find(value2, value) then
task.spawn(function() -- task.spawn() so that it wont delay other teleports
table.insert(loadedTable, value)
task.wait(1)
humanoidRootPart.CFrame = workspace[selectedMapStringValue.Value].AttackerSpawnLocations[index2].CFrame
end)
end
end
end)
value:LoadCharacter()
end