How can I make it so this spawn script spawns players in the center of the spawn point?
I'm using a free model called "Infinite Obby" which basicly is a script that add's spawn-points with stages. The problem is that when someone spawns it does not spawn them in the center of the spawn point which makes it look bad (In my opinion). I need hep making it so players will spawn in the center of a spawn point like a regular roblox spawn point would.
This is part of the script I think which needs to be edited:
01 | function warpToCheckPoint(torso, cpnum) |
02 | if cpnum = = nil then return end |
03 | if torso = = nil then return end |
04 | local cp = cpmodel:FindFirstChild( tostring (cpnum)) |
06 | local chosenCFrame = cp.CFrame |
07 | * CFrame.new(math.random(-cp.Size.X/ 2 ,cp.Size.X/ 2 ), 2.5 , math.random(-cp.Size.Z/ 2 ,cp.Size.Z/ 2 )) |
10 | torso.CFrame = chosenCFrame |
14 | if (torso.Position - cp.Position).magnitude > 3 then |
15 | torso.CFrame = chosenCFrame |
This is the whole script:
003 | local statName = "Stage" |
004 | local ModelName = "_CheckPoints" |
007 | local savingEnabled = false |
009 | local allowDeathReach = false |
012 | local victorySound = true |
020 | local cpmodel = game.Workspace:FindFirstChild(ModelName) |
021 | local cw = game.Workspace:GetChildren() |
023 | if cw [ iw ] .Name = = ModelName and cw [ iw ] ~ = cpmodel then |
024 | local copyc = cw [ iw ] :GetChildren() |
025 | for icopyc = 1 , #copyc do |
026 | copyc [ icopyc ] .Parent = cpmodel |
033 | local cpmodelc = cpmodel:GetChildren() |
034 | for j = 1 , #cpmodelc do |
035 | local cpoint = cpmodelc [ j ] |
036 | cpoint.Touched:connect( function (hit) |
037 | if hit = = nil then return end |
038 | if hit.Parent = = nil then return end |
039 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
041 | if hit.Parent:FindFirstChild( "Humanoid" ).Health < = 0 and not allowDeathReach then |
044 | local plr = game.Players:GetPlayerFromCharacter(hit.Parent) |
045 | if plr and not stop then |
046 | if plr:FindFirstChild( "CheckPointNumber" ) then |
047 | local cpnum 1 = plr:FindFirstChild( "CheckPointNumber" ).Value |
048 | local cpnum 2 = tonumber (cpoint.Name) |
049 | if cpnum 1 < cpnum 2 then |
050 | plr:FindFirstChild( "CheckPointNumber" ).Value = cpnum 2 |
051 | if plr:FindFirstChild( "leaderstats" ) then |
052 | local progressdisplay = plr:FindFirstChild( "leaderstats" ):FindFirstChild(statName) |
053 | if progressdisplay then |
054 | progressdisplay.Value = getDisplayText(cpnum 2 ) |
058 | if plr:FindFirstChild( "PlayerGui" ) then |
059 | local sound = Instance.new( "Sound" ) |
060 | sound.Name = "VictorySound" |
061 | sound.SoundId = victorySoundId |
062 | sound.Parent = plr:FindFirstChild( "PlayerGui" ) |
064 | game:GetService( "Debris" ):AddItem(sound, 5 ) |
074 | function getDisplayText(cpnum) |
075 | local displaytext = "[Error!]" |
076 | local cp = cpmodel:FindFirstChild( tostring (cpnum)) |
079 | local c = cp:GetChildren() |
081 | if c [ i ] :IsA( "BoolValue" ) and c [ i ] .Value = = true then |
085 | if cpname ~ = nil then |
086 | if cpname.Name ~ = "" then |
087 | displaytext = cpname.Name.. " - [" ..cpnum.. "]" |
089 | displaytext = "[" ..cpnum.. "]" |
092 | displaytext = "[" ..cpnum.. "]" |
098 | function warpToCheckPoint(torso, cpnum) |
099 | if cpnum = = nil then return end |
100 | if torso = = nil then return end |
101 | local cp = cpmodel:FindFirstChild( tostring (cpnum)) |
103 | local chosenCFrame = cp.CFrame |
104 | * CFrame.new(math.random(-cp.Size.X/ 2 ,cp.Size.X/ 2 ), 2.5 , math.random(-cp.Size.Z/ 2 ,cp.Size.Z/ 2 )) |
107 | torso.CFrame = chosenCFrame |
111 | if (torso.Position - cp.Position).magnitude > 3 then |
112 | torso.CFrame = chosenCFrame |
121 | function onPlayerRespawn(property, player) |
122 | if player = = nil then return end |
123 | if property = = "Character" and player.Character ~ = nil then |
124 | local char = player.Character |
125 | local torso = char:FindFirstChild( "HumanoidRootPart" ) |
128 | if torso = = nil and char ~ = nil then |
129 | torso = char:FindFirstChild( "HumanoidRootPart" ) |
134 | if torso and player ~ = nil then |
135 | local cpnum = player:FindFirstChild( "CheckPointNumber" ) |
137 | warpToCheckPoint(torso, cpnum.Value) |
140 | if savingEnabled then |
141 | if player:FindFirstChild( "PlayerGui" ) then |
142 | local save_gui = script.SaveGui:Clone() |
143 | save_gui.Parent = player:FindFirstChild( "PlayerGui" ) |
144 | save_gui.MainFrame.InteractScript.Disabled = false |
150 | game.Players.PlayerAdded:connect( function (player) |
151 | while player.Character = = nil do wait() end |
152 | local char = player.Character |
153 | while char:FindFirstChild( "HumanoidRootPart" ) = = nil do wait() end |
154 | local torso = char:FindFirstChild( "HumanoidRootPart" ) |
156 | local cpnum = Instance.new( "IntValue" ) |
157 | cpnum.Name = "CheckPointNumber" |
159 | cpnum.Parent = player |
161 | local leaderstats = Instance.new( "IntValue" ) |
162 | leaderstats.Name = "leaderstats" |
163 | leaderstats.Parent = player |
165 | local progressdisplay = Instance.new( "StringValue" ) |
166 | progressdisplay.Name = statName |
167 | progressdisplay.Value = getDisplayText(cpnum.Value) |
168 | progressdisplay.Parent = leaderstats |
170 | cpnum.Changed:connect( function () |
171 | progressdisplay.Value = getDisplayText(cpnum.Value) |
174 | onPlayerRespawn( "Character" , player) |
176 | player.Changed:connect( function (property) |
177 | onPlayerRespawn(property, player) |