- 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.
-
What is the issue?
Player character keeps spawning outside the area -
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)