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

Why dosen't the CFrame command teleport the character?

Asked by
Vik954 48
4 years ago

I made a script in the StarterCharacterScripts folder which is meant to spawn the player in a (somewhat) random location, by putting 4 Vector3s 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?

2 answers

Log in to vote
0
Answered by 4 years ago

You're only moving the HumanoidRootPart, try script.Parent:SetPrimaryPartCFrame(CFrame.new(PossiblePlaces[math.random(1,4)], Vector3.new(0, 3, 0)) instead

Ad
Log in to vote
0
Answered by 4 years ago
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

Answer this question