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

(Solved) How do I make a part's position the same as another?

Asked by 4 years ago
Edited 4 years ago

I want to make a TextButton that creates a part and sets the position to where the player is, if anything, slightly in front of it.

Here is the code I have so far:

function onclick()

    local player = game.Players.LocalPlayer
    local character = player.Character
    local mouse = player:GetMouse()
    local p = Instance.new("Part")

    local pos = character.LowerTorso.Position
    p.Parent = game.Workspace
    p.Position = Vector3.new(pos)


end

script.Parent.MouseButton1Click:Connect(onclick)

The script is a local script by the way. Any help would be appreciated! :)

EDIT: Oops! I'm an idiot lol! I was putting the Vector3 in "p.Position = Vector3.new(pos)". The solution is to have just "p.Position = pos". Sorry about that!

2 answers

Log in to vote
0
Answered by 4 years ago

Oops! I'm an idiot lol! I was putting the Vector3 in "p.Position = Vector3.new(pos)". The solution is to have just "p.Position = pos". Sorry about that!

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You can also use CFrame:

function onclick()

    local player = game.Players.LocalPlayer
    local character = player.Character
    local mouse = player:GetMouse()
    local p = Instance.new("Part")

    local pos = character.LowerTorso.Position
    p.Parent = game.Workspace
    p.CFrame = CFrame.new(pos)
end

script.Parent.MouseButton1Click:Connect(onclick)

Hope this helped!

0
Thanks for the tip! :D happyhal75 32 — 4y
0
No problem! :D TheRealPotatoChips 793 — 4y

Answer this question