How would I spawn a Map Model to specific position in this code?
Hello all! My minigame system is seeming to fail atm, and I am entirely sure as to why!
I'd like my script to be able to spawn where the "DungeonSpawn" model with the child part named "Pos" is!
When I run this, after the period of 60 seconds (intermission), it spawns the map, BUT, it spawns it at position (0,0,0) in the workspace! I done some research on the DevForums about this problem, and only found my attempt, which didn't work, so I've turned to here!
Here is my ServerScript located in the workspace!
Any and all help is appreciated!
Main focus of attention I BELIEVE is Lines 34-43, but I could be wrong!
Thank you!
001 | local minigameModule = { |
007 | local waitForChild = game.WaitForChild |
008 | local findFirstChild = game.FindFirstChild |
012 | local settingsModule = require(waitForChild(script, "Settings" )) |
013 | local onWin = ( function () |
014 | local onWinModule = findFirstChild(script, "OnWin" ) |
017 | local onWinFunction = require(onWinModule) |
019 | if type (onWinFunction) = = "function" then |
025 | local remoteEvent = waitForChild(game:GetService( "ReplicatedStorage" ), "Event" ) |
026 | local mapsStorage = waitForChild(game:GetService( "ServerStorage" ), "Maps" ):GetChildren() |
028 | local playersService = game:GetService( "Players" ) |
030 | function minigameModule.isPotentialGame() |
031 | return playersService.NumPlayers > = settingsModule.minimumPlayers |
034 | function minigameModule:chooseMap() |
035 | local chosenMap = mapsStorage [ #mapsStorage ] :Clone() |
036 | if findFirstChild(chosenMap, "Spawns" ) then |
037 | chosenMap.Parent = workspace.DungeonSpawner |
038 | chosenMap.PrimaryPart.Position = Vector 3. new(game.Workspace.DungeonSpawner.Pos.Position) |
039 | chosenMap:MakeJoints() |
040 | self.currentMap = chosenMap |
045 | function minigameModule:spawnPlayers() |
046 | local playersAlive = self.playersAlive |
047 | local spawns = self.currentMap.Spawns:GetChildren() |
048 | for index = 1 , #playersAlive do |
049 | local playerData = playersAlive [ index ] |
050 | playerData.playerHumanoidRoot.CFrame = spawns [ math.random(#spawns) ] .CFrame |
054 | function minigameModule:runIntermission() |
055 | if settingsModule.intermissionTime > 0 then |
056 | for currentTime = math.floor(settingsModule.intermissionTime), 0 , - 1 do |
057 | remoteEvent:FireAllClients( "Timer" , currentTime) |
061 | remoteEvent:FireAllClients( "CeaseGUIs" ) |
064 | function minigameModule:getAlivePlayers() |
065 | local playersAlive = { } |
066 | for index, currentPlayer in next , playersService:GetPlayers() do |
067 | local playerCharacter = currentPlayer.Character |
068 | if playerCharacter then |
069 | local playerHumanoidRoot = findFirstChild(playerCharacter, "HumanoidRootPart" ) |
070 | local playerHumanoid = findFirstChild(playerCharacter, "Humanoid" ) |
071 | if playerHumanoid and playerHumanoidRoot then |
072 | table.insert(playersAlive, { |
073 | player = currentPlayer, |
074 | playerHumanoid = playerHumanoid, |
075 | playerHumanoidRoot = playerHumanoidRoot |
083 | function minigameModule:isLegalGame() |
084 | if #self:getAlivePlayers() > = settingsModule.minimumPlayers then |
089 | function minigameModule:queryGameStart() |
090 | if self.gameRunning then |
092 | elseif self.isPotentialGame() then |
093 | self.gameRunning = true |
094 | remoteEvent:FireAllClients( "CeaseGUIs" ) |
095 | self:runIntermission() |
097 | if self:isLegalGame() then |
098 | if settingsModule.roundDuration > 0 then |
100 | local currentMap = self:chooseMap() |
101 | local mapWeapons = findFirstChild(currentMap, "Weapons" ) |
103 | local playersAlive = self:getAlivePlayers() |
104 | self.playersAlive = playersAlive |
106 | for index = 1 , #playersAlive do |
107 | local currentPlayer = playersAlive [ index ] |
108 | local backpack = findFirstChild(currentPlayer.player, "Backpack" ) |
110 | if backpack and mapWeapons then |
111 | for index, weapon in next , mapWeapons:GetChildren() do |
112 | weapon:Clone().Parent = backpack |
117 | connection = currentPlayer.playerHumanoid.Died:connect( function () |
118 | connection:disconnect() |
119 | table.remove(playersAlive, index) |
120 | if #playersAlive < 2 then |
121 | local winner = playersAlive [ 1 ] |
123 | self:endGame(winner.player.Name .. " has won!" , winner.player) |
125 | self:endGame( "No one has won!" ) |
137 | remoteEvent:FireAllClients( "Message" , currentMap.Name .. " was chosen!" , 5 ) |
139 | for currentTime = settingsModule.roundDuration, 0 , - 1 do |
140 | if not self.gameRunning then |
143 | remoteEvent:FireAllClients( "Timer" , currentTime) |
146 | self:endGame( "The timer ran out! No one has won!" ) |
150 | self:endGame( "Not enough players alive to begin the round!" ) |
153 | local remainingPlayers = settingsModule.minimumPlayers - playersService.NumPlayers |
154 | remoteEvent:FireAllClients( "Message" , "Waiting for " .. remainingPlayers .. " player" .. (remainingPlayers > 1 and "s" or "" ) .. " to join." ) |
158 | function minigameModule:endGame(outputMessage, winner) |
159 | if self.gameRunning then |
161 | self.gameRunning = false |
162 | self.currentMap:Destroy() |
163 | self.currentMap = nil |
165 | if winner and onWin then |
169 | for index, player in next , playersService:GetPlayers() do |
170 | player:LoadCharacter() |
175 | remoteEvent:FireAllClients( "Message" , outputMessage, 5 ) |
179 | self:queryGameStart() |
183 | function minigameModule:removePlayer(player) |
184 | if self.gameRunning then |
185 | for index = 1 , #self.playersAlive do |
186 | if self.playersAlive [ index ] .player = = player then |
187 | table.remove(self.playersAlive, index) |
188 | if #self.playersAlive < = 1 then |
189 | self:endGame( "Not enough players to continue the game." ) |
197 | playersService.PlayerAdded:connect( function () |
198 | minigameModule:queryGameStart() |
201 | playersService.PlayerRemoving:connect( function (player) |
202 | minigameModule:removePlayer(player) |