Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make it so this spawn script spawns players in the center of the spawn point?

Asked by
262187 45
10 years ago

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:

01function warpToCheckPoint(torso, cpnum)
02    if cpnum == nil then return end
03    if torso == nil then return end
04    local cp = cpmodel:FindFirstChild(tostring(cpnum))
05    if cp ~= nil then
06        local chosenCFrame = cp.CFrame  -- Below is the offset
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))
08                                        -- Above is the offset  ^
09 
10        torso.CFrame = chosenCFrame
11        wait()
12        for k = 1, 10 do
13            if torso ~= nil then
14                if (torso.Position - cp.Position).magnitude > 3 then
15                    torso.CFrame = chosenCFrame
View all 22 lines...

This is the whole script:

001------------ OPTIONS ------------
002 
003local statName = "Stage"            -- You can change this to "Level" or "Chapter" or "Section"
004local ModelName = "_CheckPoints"    -- Name of model that stores checkpoint spawnblocks
005                                    -- (You don't HAVE to change this! This is only if you want to.)
006 
007local savingEnabled = false     -- Having this set to true will let players save their checkpoint in your game!
008 
009local allowDeathReach = false   -- If a player dies but still touches a checkpoint,
010                                -- It won't count if this is set to false.
011 
012local victorySound = true       -- If you want a victory sound for checkpoints, change this to lowercase true.
013local victorySoundId = "rbxassetid://12222253"
014 
015    ---------------------------------
View all 180 lines...
0
Please code block everything correctly. DigitalVeer 1473 — 10y
0
I agree w/ DigitalVeer. alphawolvess 1784 — 10y
0
Sorry first time post, fixed it. 262187 45 — 10y

1 answer

Log in to vote
1
Answered by
noliCAIKS 210 Moderation Voter
10 years ago

On this line:

1local chosenCFrame = cp.CFrame * CFrame.new(math.random(-cp.Size.X/2,cp.Size.X/2), 2.5, math.random(-cp.Size.Z/2,cp.Size.Z/2))

Isn't it the math.random stuff that causes it not to spawn Directly on top of it? Why would you even bother with that if you just want it to spawn right on top? Also, the vertical offset of 2.5 seems a bit low. Since half of the torso's height + the height of the legs is 3, you could try using 3 + cp.Size.Y / 2 to Spawn it directly on top of the Spawn, or 3 + cp.Size.Y / 2 + 0.5 to spawn it a half stud above it, etc. I'd just do this:

1function warpToCheckPoint(torso, cpnum)
2    if cpnum == nil then return end
3    if torso == nil then return end
4    local cp = cpmodel:FindFirstChild(tostring(cpnum))
5    if cp ~= nil then
6        torso.CFrame = cp.CFrame * CFrame.new(0, 3 + cp.Size.Y / 2 + 0.5, 0)
7    end
8end
0
Thanks this worked! 262187 45 — 10y
0
@262187 In that case, please select the option to accept my answer. I would appreciate it. noliCAIKS 210 — 10y
Ad

Answer this question