How do i make my placing tool's placements account for orientation

ive been trying to make a placement tool, “hammer” and it works for the mostpart, but im trying to take in account the rotations of the parts so that they dont float and arent clipped into the floor

it works by putting the part on the floor where the mouse is, and moves it up half the part’s height. this does not work when i orient it. pls help

local script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local event = tool.Clicked

local userinputservice = game:GetService("UserInputService")

local basepart = Instance.new("Part")
basepart.Size = Vector3.new(14.625, 8.25, 2)
basepart.Parent = game.ReplicatedStorage

local debounce = false

tool.Equipped:Connect(function()
	basepart.Parent = workspace
	basepart.CanCollide = false
	basepart.CanQuery = false
	basepart.Transparency = 0.5
	basepart.Anchored = true
	
	repeat
		wait()
		local lastorientation = basepart.Orientation
		basepart.Position = mouse.Hit.Position + Vector3.new(0,basepart.Size.Y/2,0) --how to make this line account for all rotations
	until
	true == false
end)

userinputservice.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R then
		basepart.Orientation += Vector3.new(0,45,0)
	end
	if input.KeyCode == Enum.KeyCode.T then
		basepart.Orientation += Vector3.new(45,0,0)
	end
	if input.KeyCode == Enum.KeyCode.Y then
		basepart.Orientation += Vector3.new(0,0,45)
	end
	if input.KeyCode == Enum.KeyCode.X then
		basepart.Orientation = Vector3.new(0,0,0)
	end
end)

mouse.Button1Down:Connect(function()
	if game.Players:GetPlayerFromCharacter(tool.Parent) then
		if debounce == false then
			event:FireServer(basepart.Position,basepart.Orientation)
			debounce = true
			wait(5)
			debounce = false
		else
			basepart.Color = Color3.new(1, 0, 0.0156863)
			local newsound = Instance.new("Sound")
			newsound.Parent = game.SoundService
			newsound.SoundId = "rbxassetid://9066167010"
			newsound:Play()
			game.Debris:AddItem(newsound,1)
			wait(0.5)
			basepart.BrickColor = BrickColor.new("Medium stone grey")
		end
	end
end)

tool.Unequipped:Connect(function()
	basepart.Parent = game.ReplicatedStorage
end)

edit: completely ignore lastorientation

ok i fixed it by just repeating going up until :getpartsinpart was length 0

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.