Placement tool rotate

I’m making a placement tool but I’m having trouble implementing a rotate function into the placement. Can anyone help me?
Code:

LocalScript "PlacementScript"

local mouse = game.Players.LocalPlayer:GetMouse()
local off = false

script.Parent.Equipped:Connect(function(toolMouse)
	if mouse ~= nil then
		local clonedBrick = game.ReplicatedStorage.ConcreteBarrier:Clone()
		mouse.TargetFilter = clonedBrick
		clonedBrick.Transparency = .5
		clonedBrick.CanCollide = false
		clonedBrick.Parent = workspace

		while mouse ~= nil do
			clonedBrick.Position = mouse.Hit.p + Vector3.new(0, 1.25, 0)
			wait()
			if off then
				clonedBrick:Destroy()
				off = false
				break
			end
		end
	end
end)

script.Parent.Activated:Connect(function()
	local BrickToPlace = game.ReplicatedStorage.ConcreteBarrier:Clone()
	local pos = mouse.Hit.p + Vector3.new(0, 1.25, 0)
	script.Parent.AddBlock:FireServer(pos)
end)

script.Parent.Unequipped:Connect(function()
	off = true
end)

ServerScript "FireEvent"

script.Parent.AddBlock.OnServerEvent:Connect(function(plr, pos)
	local btp = game.ReplicatedStorage.ConcreteBarrier:Clone()
	btp.Parent = workspace
	btp.CanCollide = true
	btp.Position = pos
	btp.Name = plr.Name.."'s Barrier"
end)

script.Parent.RemoveBlock.OnServerEvent:Connect(function(plr, block)
	if block.Name == plr.Name then
		block:Destroy()
	end
end)

image

If you would like to rotate a part, you have to use CFrame.Angles() to multiply it to the CFrame of the part

Example:

local part = game.Workspace.Part
part.CFrame = part.CFrame * CFrame.Angles(0,0,math.rad(90)) -- Rotates the part by 90 degrees. and math.rad is used to convert the number to Radians

Hope it helps!

And so your example would set the rotation increment to 90? Thanks for the help!

1 Like