I made a script in the StarterCharacterScripts
folder which is meant to spawn the player in a (somewhat) random location, by putting 4 Vector3
s in an array, selecting one of them and moving the HumanoidRootPart
to the selected location by using the CFrame
command.
Here's my code:
local HumanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart") local PossiblePlaces = {Vector3.new(-350, 3, -350), Vector3.new(-350, 3, 350), Vector3.new(350, 3, 350), Vector3.new(350, 3, -350)} HumanoidRootPart.CFrame = CFrame.new(PossiblePlaces[math.random(1, 4)], Vector3.new(0, 3, 0))
Can anyone help?
You're only moving the HumanoidRootPart, try script.Parent:SetPrimaryPartCFrame(CFrame.new(PossiblePlaces[math.random(1,4)], Vector3.new(0, 3, 0))
instead
local humanoidrootpart = script.Parent:WaitForChild("HumanoidRootPart") local possibleplaces = math.random(1,4) if possibleplaces == 1 then humanoidrootpart.CFrame = CFrame.new(-350, 3, -350) elseif possibleplaces == 2 then humanoidrootpart.CFrame = CFrame.new(-350, 3, 350) elseif possibleplaces == 3 then humanoidrootpart.CFrame = CFrame.new(350, 3, 350) elseif possibleplaces == 4 then humanoidrootpart.CFrame = CFrame.new(350, 3, -350) end
sorry but we need to check every single possibility, atleast the way i know it