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)
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)