How to stop the Player character from spawning outside certain area?

  1. What do you want to achieve?

I want to make the player character spawn within the area that is covered by the “ParachuteArea” part. Do make note that the Player Character is added in “PlayersCharacter” Folder. I also do not want to use Spawn locations either as it will cause problems in my game.

  1. What is the issue?
    Player character keeps spawning outside the area

  2. What solutions have you tried so far?
    I tried adding the waiting time and in case the character is glitching out.

local MapFolder = script.Parent
local Map = MapFolder.Map

local ParachuteArea = Map.ParachuteArea

local minParachuteAreaVectorPosition = ParachuteArea.Position
local maxParachuteAreaVectorPosition = minParachuteAreaVectorPosition + ParachuteArea.Size

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events
local MapParachuteSignalBindableEvent = Events.MapParachuteSignalBindableEvent

local function onCharacterAdded(Character)
	
	math.randomseed(os.time())
	
	local randomXPosition = math.random(minParachuteAreaVectorPosition.X, maxParachuteAreaVectorPosition.X)
	local randomZPosition = math.random(minParachuteAreaVectorPosition.Z, maxParachuteAreaVectorPosition.Z)
	
	local NewVectorPosition = Vector3.new(randomXPosition, minParachuteAreaVectorPosition.Y, randomZPosition)
	
	local NewCFrame = CFrame.new(NewVectorPosition)
	
	Character.PrimaryPart.Anchored = true
	
	Character:SetPrimaryPartCFrame(NewCFrame)
	
	MapParachuteSignalBindableEvent:Fire(Character.Name)
	
	wait(0.5)
	
	Character.PrimaryPart.Anchored = false
	
end

workspace.PlayersCharacter.ChildAdded:Connect(onCharacterAdded)

try waiting a physics step before teleporting the character
there’s an example of teleporting a character as soon as it spawns here

Doesn’t seem to work to be honest, here’s the adjusted code for you to double check:

local function onCharacterAdded(Character)

	math.randomseed(os.time())
	
	local randomXPosition = math.random(minParachuteAreaVectorPosition.X, maxParachuteAreaVectorPosition.X)
	local randomZPosition = math.random(minParachuteAreaVectorPosition.Z, maxParachuteAreaVectorPosition.Z)
	
	local NewVectorPosition = Vector3.new(randomXPosition, minParachuteAreaVectorPosition.Y, randomZPosition)
	
	local NewCFrame = CFrame.new(NewVectorPosition)
	
	Character.PrimaryPart.Anchored = true
	
	RunService.Stepped:Wait()
	
	Character:SetPrimaryPartCFrame(NewCFrame)
	
	MapParachuteSignalBindableEvent:Fire(Character.Name)
	
	Character.PrimaryPart.Anchored = false

end

.Position is the center of the part, so if you want to spawn in the radius of the part, you need to math random to the .position half of the part’s size

local spawnPos = Vector3.new(parachutePart.Position.X + math.random(-parachutePart.Size.X/2, parachutePart.Size.X/2), parachutePart.Position.Y, parachutePart.Position.Z + math.random(-parachutePart.Size.Z/2, parachutePart.Size.Z/2) )

Ah. I was about to write that. I forgot to adjust .Position before asking the question, nevertheless I will mark your answer as solution.