Hi everyone! Thanks for taking your time to read my question. I've got the following problem: I made a placement system to place on a 3 stud grid. It works perfect unless one thing: when you place 3 blocks in the air (one on the ground and the other two on top of it) you can place a part against the highest part in the air when placing it in the x axis side. When i place it on the z axis side, the part appears in the block that i'm pointing my mouse on instead next to it.

I hope that explains the problem.

Here is the script that i currently have. It's activated by enabling the script through a gui. I know it is not fe but i will convert it if i got it working.

local part = script.Item.Value
part.Parent = workspace
--[[
part.BrickColor = BrickColor.Red()
part.Size = Vector3.new(5,5,5)
part.CanCollide = false
part.Anchored = true
]]
local player = game.Players.LocalPlayer

local mouse = player:GetMouse()
mouse.TargetFilter = part
local ready = false
local gridSize = 3
local CurrentYRot = 0
local rotation = CFrame.Angles(math.rad(0), math.rad(0), math.rad(0))

function roundNum(num)
local min = math.floor(num)
local max = math.ceil(num)
    if num-min > max-num then
        return max
    elseif num-min < max-num then
        return min
    else
        return max
    end
end


print("equiped")
ready = true
part.Transparency = 0.5

 
local function onUnequip()
	print("uneqipped")
 	ready = false
	part.Transparency = 1
	script.Parent.Enabled = true
	script.Disabled = true
end
 
local function onActivate()
 	print("activated")
end
 
local function onDeactivate()
	print("deactivated")
	local c = part:Clone()
	c.Parent = workspace
	c.CanCollide = true
	c.Transparency = 0
	c.Anchored = true
	onUnequip()
end
mouse.Move:connect(function()

	if ready == true then
		pos = mouse.Hit.p
		pX = roundNum(pos.X/gridSize) * gridSize
		pY = (roundNum(pos.Y/gridSize) * gridSize) -2
		pZ = roundNum(pos.Z/gridSize) * gridSize
		part.CFrame = rotation + Vector3.new(pX, pY + 2.5, pZ)
		 
	end
end)

mouse.Button1Up:connect(function()
	if ready then
		onDeactivate()
	end
end)




function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.R and ready then
		CurrentYRot = CurrentYRot + 90
		rotation = CFrame.Angles(math.rad(0), math.rad(CurrentYRot), math.rad(0))
		
		pos = mouse.Hit.p
		pX = roundNum(pos.X/gridSize) * gridSize
		pY = (roundNum(pos.Y/gridSize) * gridSize) -2
		pZ = roundNum(pos.Z/gridSize) * gridSize
		part.CFrame = rotation + Vector3.new(pX, pY + 2.5, pZ + 1)
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

Thanks for your help and time, Jonas (marketmanager1 on roblox)

1 comment

0

bump