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

How would I make a part face the same direction my Torso is facing?

Asked by 9 years ago

So I made this script and when I activate it, the part spawns where i want yes. But it spawns facing in the same direction. I want it to face the direction my torso is facing. Please help, you may add on to my script :)

player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.Move:connect(function()
    local target = mouse.Target
    if target.Name == "Grass" then
            print("Spawning sand...")
        else
    print("You can only use sand on grass!")
    end
end)

mouse.KeyDown:connect(function(key)
    local target = mouse.Target
    if key == "c" and target.Name == "Grass" then

        local sand = Instance.new("Part", game.Workspace)
        sand.Name = "Sand"
        sand.Anchored = true
        sand.BrickColor = BrickColor.new("Pastel brown")
        sand.Material = "Sand"
        sand.Size = Vector3.new(8, 10, 2)

    -- Surfaces:

        sand.BackSurface = "Smooth"
        sand.BottomSurface = "Smooth"
        sand.FrontSurface = "Smooth"
        sand.LeftSurface = "Smooth"
        sand.RightSurface = "Smooth"
        sand.TopSurface = "Smooth"

    -- Position:

        sand.CFrame = CFrame.new(mouse.Hit.p) + Vector3.new(0, 4.8, 0)
    end
end)


0
Please help, this is really important! Alucifer 45 — 9y
0
Remember that all surfaces except the top and bottom are smooth by default. You could get rid of at least four lines that way. funyun 958 — 9y

2 answers

Log in to vote
2
Answered by 9 years ago

One of the methods of CFrame lets you create a CFrame positioned at position and looking at point.

CFrame.new(Vector3 position, Vector3 point)

With this in mind, you could just use mouse.Hit.p for the position and the lookVector property of the character's Torso to make sure the part faces the direction of where the player's torso is looking.

sand.CFrame = CFrame.new(mouse.Hit.p,player.Character.Torso.CFrame.lookVector) + Vector3.new(0, 4.8, 0)

I hope my answer helped you. If it did, be sure to accept it.

Ad
Log in to vote
0
Answered by 9 years ago
player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.Move:connect(function()
    local target = mouse.Target
    if target.Name == "Grass" then
            print("Spawning sand...")
        else
    print("You can only use sand on grass!")
    end
end)

mouse.KeyDown:connect(function(key)
    local target = mouse.Target
    if key == "c" and target.Name == "Grass" then

        local sand = Instance.new("Part", game.Workspace)
        sand.Name = "Sand"
        sand.Anchored = true
        sand.BrickColor = BrickColor.new("Pastel brown")
        sand.Material = "Sand"
        sand.Size = Vector3.new(8, 10, 2)

    -- Surfaces:

        sand.BackSurface = "Smooth"
        sand.BottomSurface = "Smooth"
        sand.FrontSurface = "Smooth"
        sand.LeftSurface = "Smooth"
        sand.RightSurface = "Smooth"
        sand.TopSurface = "Smooth"

    -- Position:

        sand.CFrame = CFrame.new(mouse.Hit.p) + Vector3.new(0, 4.8, 0)

    -- Rotation:

        sand.Rotation = Vector3.new(player.Character.Torso.Rotation)

    end
end)

0
Nothing to explain, basically just changes the Vector3 Rotation of the sand to the Torso's rotation. HungryJaffer 1246 — 9y
0
Already tried that, doesnt work Alucifer 45 — 9y
0
Did anything come out on output when you tried that? HungryJaffer 1246 — 9y
0
nope Alucifer 45 — 9y

Answer this question