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

How exactly do local parts work, when using CFrame?

Asked by
joalars2 107
8 years ago

I've never understood it. Whenever i try to CFrame a local part, it moves somewhere completely different from where i want it to be... Help?

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
        local bin = Instance.new("Message",char)
        local part = Instance.new("Part",bin)
        part.CFrame = CFrame.new(0,10,0)
    end)
end)

The code above puts it around my spawn instead of around the co-ordinates 0,10,0

I am REALLY confused.

0
Players often spawn around the coordinates 0,0,0 so you might be checking it wrong. Look at it's properties instead. TheDeadlyPanther 2460 — 8y
0
I put a custom spawnpoint... joalars2 107 — 8y
0
Oke. Try doing my answer. TheDeadlyPanther 2460 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

Try this and tell me if it works. objectspace is the position the character spawned at (measured at ground level), and positions the part to the given position by subtracting the objectspace.

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
    local objectspace  = char.Torso.Position - Vector3.new(0,3,0)
    local function coord(position)
        return position - objectspace
    end

        local bin = Instance.new("Message",char)
        local part = Instance.new("Part",bin)
        part.CFrame = CFrame.new(coord(Vector3,new(0,10,0)))
    end)
end)
Ad
Log in to vote
-1
Answered by 8 years ago

CFrame has two parameters, both being Vector3 values. It can stuff up if your provide 3 values, or only one of them. Parameter 1 being it's position, and Parameter 2 being where it's facing.

part.CFrame = CFrame.new(Vector3.new(0,10,0),Part.Position + Vector3.new(0,0,2)) --the 2nd parameter: parts stuff up if you make them look at themselves :/
0
Thanks, i'll try that. joalars2 107 — 8y
0
Hmm, i think the local parts are placed locally to where the player is spawned... I'll try making a script that positions it based on the players spawnpoint subtracted by the CFrame of where i want it. (That way i can re-use it really easily <3) joalars2 107 — 8y
0
I'll make it as simple as just placing the parts in a folder. joalars2 107 — 8y

Answer this question