In my game script, I coded for players to teleport to chosen map but the players aren't teleporting?
In my game script of my minigame, the players should go to the map which is chosen randomly, however when I test the game it says "Teleporting Players" however the players aren't being teleported. Is there and error on my gamescript?
My GameScript:
001 | local maps = game.ServerStorage:WaitForChild( "Maps" ):GetChildren() |
002 | local lobby = game.Workspace:WaitForChild( "Lobby" ) |
003 | local message = game.Workspace:WaitForChild( "Message" ) |
004 | local numplayers = game.Workspace:WaitForChild( "NumPlayers" ) |
005 | local chosenmap = game.Workspace:WaitForChild( "ChosenMap" ) |
006 | local selected = game.Workspace:WaitForChild( "SelectedMap" ) |
007 | local timer = game.Workspace:WaitForChild( "Timer" ) |
008 | local playerNeeded = 1 |
010 | function deleteLastMap() |
011 | selected:ClearAllChildren() |
014 | function checkPlayers() |
015 | if numplayers.Value > = playerNeeded then |
022 | function getAlivePlayers() |
024 | local players = game.Players:GetPlayers() |
025 | for i = 1 ,#players do |
026 | if players [ i ] .Settings.AFK.Value ~ = false then |
027 | if players [ i ] .Character ~ = nil then |
028 | if players [ i ] .Character.Humanoid.Health ~ = 0 then |
029 | if players [ i ] .Settings.Playing.Value ~ = false then |
041 | local players = game.Players:GetPlayers() |
042 | for i = 1 ,#players do |
043 | if players [ i ] .Settings.AFK.Value ~ = false then |
044 | if players [ i ] .Character ~ = nil then |
045 | if players [ i ] .Character.Humanoid.Health ~ = 0 then |
046 | if players [ i ] .Settings.Winners.Value ~ = false then |
056 | function intermission() |
059 | message.Value = "Intermission: " ..i.. " seconds!" |
064 | message.Value = "Choosing map..." |
066 | if maps [ i ] :isA( "Model" ) then |
067 | chosenmap.Value = maps [ math.random( 1 ,#maps) ] .Name |
072 | function displayChosen() |
073 | message.Value = "Map Chosen: " ..chosenmap.Value.. "!" |
076 | function loadMinigame() |
077 | message.Value = "Loading map..." |
078 | local clone = game:GetService( "ServerStorage" ).Maps:FindFirstChild(chosenmap.Value) |
079 | clone:Clone().Parent = selected |
083 | local mapSpawn = selected:FindFirstChild(chosenmap.Value).Spawns:GetChildren() |
084 | local lobbySpawn = game.Workspace.Lobby:GetChildren() |
085 | local players = game.Players:GetPlayers() |
087 | message.Value = "Teleporting Players..." |
091 | for i = 1 ,#players do |
092 | if players [ i ] ~ = nil then |
093 | if players [ 1 ] .Settings.AFK.Value~ = false then |
094 | if players [ i ] .Character ~ = false then |
095 | if players [ i ] .Character.Humanoid.Health~ = 0 then |
096 | local ransp = mapSpawn [ math.random( 1 ,#mapSpawn) ] .CFrame + Vector 3. new( 0 , 3 , 0 ) |
097 | players [ i ] .Character.HumanoidRootPart.CFrame = ransp |
099 | if players [ i ] ~ = nil then |
100 | if players [ i ] .Character ~ = nil then |
101 | players [ i ] .Character.HumanoidRootPart.CFrame = ransp |
106 | if players [ i ] ~ = nil then |
107 | if players [ i ] .Character ~ = nil then |
108 | players [ i ] .Character.HumanoidRootPart.CFrame = ransp |
125 | message.Value = "The game will start in" ..i.. "seconds!" |
128 | message.Value = "Go!" |
129 | for i = 1 ,#players do |
130 | if players [ i ] ~ = nil then |
131 | if players [ i ] .Settings.AFK.Value ~ = true then |
132 | if players [ i ] .Character ~ = nil then |
133 | players [ i ] .Settings.Playing.Value = true |
139 | timer.Value = selected:FindFirstChild(chosenmap.Value).Timer.Value |
140 | while timer.Value ~ = 0 and getAlivePlayers()~ = 0 do |
142 | message.Value = "Time left:" ..i.. "seconds!" |
143 | timer.Value = timer.Value- 1 |
146 | message.Value = "Time's up!" |
148 | for i,v in pairs (players) do |
149 | if v.Settings.Winner.Value = = true then |
150 | table.insert(winners.players [ i ] ) |
151 | if #winners = = 1 then |
152 | message.Value = v.Name.. "survived!" |
154 | message.Value = "The winner will receive 50 credits!" |
155 | v.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1 |
156 | v.leaderstats.Credits.Value = v.leaderstats.Credits.Value + 50 |
159 | elseif #winners> = 2 then |
160 | message.Value = "Many players have survived" |
162 | message.Value = "Each player will receive 25 credits!" |
163 | v.Settings.Winner.Value = false |
164 | v.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1 |
165 | v.leaderstats.Credits.Value = v.leaderstats.Credits.Value + 25 |
173 | for i = 1 ,#players do |
174 | if players [ i ] ~ = nil then |
175 | if players [ i ] .Character ~ = nil then |
176 | local ransp = lobbySpawn [ math.random( 1 ,#lobbySpawn) ] .CFrame+Vector 3. new( 0 , 3 , 0 ) |
177 | players [ i ] .Character.HumanoidRootPart.CFrame = ransp |
188 | if checkPlayers() then |
197 | if checkPlayers() then |
200 | table.remove(winners) |
Teleporting script in game script:
02 | local mapSpawn = selected:FindFirstChild(chosenmap.Value).Spawns:GetChildren() |
03 | local lobbySpawn = game.Workspace.Lobby:GetChildren() |
04 | local players = game.Players:GetPlayers() |
06 | message.Value = "Teleporting Players..." |
11 | if players [ i ] ~ = nil then |
12 | if players [ 1 ] .Settings.AFK.Value~ = false then |
13 | if players [ i ] .Character ~ = false then |
14 | if players [ i ] .Character.Humanoid.Health~ = 0 then |
15 | local ransp = mapSpawn [ math.random( 1 ,#mapSpawn) ] .CFrame + Vector 3. new( 0 , 3 , 0 ) |
16 | players [ i ] .Character.HumanoidRootPart.CFrame = ransp |
18 | if players [ i ] ~ = nil then |
19 | if players [ i ] .Character ~ = nil then |
20 | players [ i ] .Character.HumanoidRootPart.CFrame = ransp |
25 | if players [ i ] ~ = nil then |
26 | if players [ i ] .Character ~ = nil then |
27 | players [ i ] .Character.HumanoidRootPart.CFrame = ransp |
Are there any errors in the code which is stopping my player from teleporting. When I tested the game everything worked, just that the players didn't teleport to the map which was cloned/
Thank You and Help is appreciated