Hello, I am making an Minigame. I made an script. sometimes its not working but sometimes its working! Here is the script! I think i am correct but why its not working sometimes?
maps = game.ServerStorage.Maps:GetChildren() map = maps[math.random(1, #maps)] wait(3) map:Clone().Parent = game.Workspace game.Workspace.Message.Value = "The Game is Starting!" wait(3) for i, Player in pairs(game.Players:GetPlayers()) do print(Player.Name) if Player.Character then Player.Character:MoveTo(workspace:FindFirstChild(map.Name).Spawns:GetChildren()[math.random(1, #workspace:FindFirstChild(map.Name).Spawns:GetChildren())].Position) end end
Apparently one of the children of workspace(map.Name).Spawns is a Model, and other are Parts.
You should browse through all of them and set a PrimaryPart for each one to the part you want the players to spawn on.
maps = game.ServerStorage.Maps:GetChildren() map = maps[math.random(1, #maps)] wait(3) map:Clone().Parent = game.Workspace game.Workspace.Message.Value = "The Game is Starting!" wait(3) for i, Player in pairs(game.Players:GetPlayers()) do print(Player.Name) if Player.Character then local spawns = workspace:FindFirstChild(map.Name).Spawns:GetChildren() local randomSpawn = spawns[math.random(1, #spawns) local targetPos = randomSpawn:IsA("BasePart") and randomSpawn.Position or randomSpawn.ClassName == "Model" and (randomSpawn.PrimaryPart and randomSpawn.PrimaryPart.Position or randomSpawn:FindFirstChildOfClass("Part").Position) Player.Character:MoveTo(targetPos) end end