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

Vector3 and CFrame conversion?

Asked by 9 years ago

Hiaa guys. Sorry again sorry for all the questions ;). Quick quesion here, about Vector3 and CFrame values. I want to know how to convert a value from CFrame to Vector3 and vice - versa. Here's an example:

wait(2)
blue = game.Workspace.BlueSpawn
red = game.Workspace.RedSpawn
Var = 0
players = game.Players:GetChildren()

function SpwnTele()
    print(player.Value.Value)
        if player.Value.Value=="blue" then
        player.Character.Torso.CFrame = CFrame.new(Vector3.new(blue.Position)) --heres the line I need help with
        print(player.Character.Torso.CFrame)
        else
        player.Character.Torso.CFrame = CFrame.new(Vector3.new(red.Position)) --and this one too
        print(player.Character.Torso.CFrame)
        end
    end

for i,v in pairs(players) do
    if Vteam==nil then
        player = v
        Vteam = Instance.new("StringValue")
        Vteam.Parent = v
        Var = math.random(1,2)
        if Var==1 then
            Vteam.Value = "red"
            SpwnTele()
        elseif Var==2 then
            Vteam.Value = "blue"
            SpwnTele()
        end
    end
end


Sorry if the script is a bit long. If you find a errors within the script, speak up! (BTW the script is supposed to create a string value for each player then pick a random team color, from which the player will be teleported to the corresponding Part with that color.) THX!!

1 answer

Log in to vote
8
Answered by 9 years ago

CFrame values have two Vector3 values in it:

1) The position the part is positioned at

2) The position that the part is facing

To get the position:

local pos = part.CFrame.p

To get where it is facing:

local pos = part.CFrame.LookVector

-- or, if you want individual numbers

local posX, posY, posZ = part.CFrame.X, part.CFrame.Y, part.CFrame.Z
0
And how would I use this method of conversion in my script? LateralLace 297 — 9y
1
I just gave it to you. The values inside CFrame values are Vector3 values, so you don't really need to convert, you just need to index them. TheDeadlyPanther 2460 — 9y
0
Well... I guess it's good enough. LateralLace 297 — 9y
0
(Vector3 expected, got CFrame)or(CFrame expected, got Vector3) when i try this User#27824 0 — 5y
0
Dude you're a GOD Shounak123 461 — 3y
Ad

Answer this question