So I am making a game loop and in this game loop, it enables a separate script to teleport any players that died to a random spawn however it will only load the character and nothing else not even an error. (Note: I am using an object value to tell the script what the map object is.)
ReplicatedStorage = game:GetService("ReplicatedStorage")
GameOn = ReplicatedStorage.Game
Maps = ReplicatedStorage.Map -- Get Map name from Object Value
game.CharacterAdded:Connect(function(char)
repeat wait() until char:WaitForChild("Humanoid")
char.Humanoid.Died:Connect(function() -- Making sure that this happens only when death
if GameOn.Value == false then
char:LoadCharacter() -- Loading the character
else
wait(3)
char:LoadCharacter() -- Loading the character
end
local Spawns = Maps.Value:FindFirstChild('Spawns'):GetChildren() -- Get spawns
local RandomSpawn = Spawns[math.random(1, #Spawns)] -- Pick a Random Spawn
if char:FindFirstChild('Humanoid') and char then
char.HumanoidRootPart.CFrame = RandomSpawn.CFrame -- Put player on picked spawn
end
end)
end)

6 comments
Whats the error code and what line is it?
there is no error it just does that
I just finished reading your code. I dont know what you were thinking, this is confusing to me, like why are you even using a for loop with the value name Players and not use it? Why even have that for loop at all? Its basically spawning the player multiple times it seems
Do you understand your own code,?
Before i help you, please fix your code, like dont use repeat until for checking for an instance, use waitforchild, char:WaitForChild"Humanoid", this way, it doesnt execute code until its loaded
kinda but not really my understanding of code is pretty limited and even with that I can understand what half of this is supposed to do but some of the code maybe some useless garbage that I am not noticing.