Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)


2 comments

0

Please help, this is really important!

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.

2 answers

✓ Accepted answer

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.

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)

4 comments

0

Nothing to explain, basically just changes the Vector3 Rotation of the sand to the Torso's rotation.

0

Already tried that, doesnt work

0

Did anything come out on output when you tried that?

0

nope

This discussion is preserved as it was. New answers, comments, and votes are closed.