So I made an building system so you can decorate the inside of your house, you can place items on the floor same for the walls and roof. The system works kinda simple you move around a model then you can place it out with a confirm button. After that if you wanna move the same model again you simply just click it and you will be able to move it again. But here is the issue that when you pickup the model to move it again it don’t keep the last position it was in, so if you for an example put out an chair on the wall and rotated it 90 degrees when you click on it, the model snaps back to the orginal cframe of the model.
Kinda obvious but that is what I need help with I have no clue how I would actually keep the last CFrame correct with my current system. Any help is appreciated as I am trash at CFrame and so on.
Btw when you click the model the system removes it and spawns in another replica of it but it keeps the CFrame but as soon as I start to “move” it with my move script you can see below that is when it snaps wrong angles and shit.
For some reason when I record in Roblox it looks like some old phone video with the worst quality but I hope you atleast can see something.
robloxapp-20230117-1401264.wmv (1.3 MB)
function placeAtMouse()
IsPlacementValid = false
if ActiveMode then
if BuildingMode then
if not LockedMode then
if mouse.Target then
if mouse.Target.Parent.Parent.Trigger.Owner.Value == player.Name or mouse.Target.Parent.Parent.Parent.Parent.Trigger.Owner.Value == player.Name then
local unitRay = workspace.CurrentCamera:ScreenPointToRay(mouse.X, mouse.Y, 0)
local players = game:GetService("Players")
local Blacklist = {}
local CurrentRoom = nil
for i,v in pairs(game.Workspace.Houses:GetChildren()) do
if v.Trigger.Owner.Value == player.Name then
CurrentRoom = v.Room
end
end
for i,v in pairs(CurrentRoom:GetChildren()) do
if v.Name == "DetectionArea" then
table.insert(Blacklist, v)
end
end
table.insert(Blacklist, PickedObject)
for i,v in pairs(players:GetChildren()) do
local character = v.Character
table.insert(Blacklist, character)
for e,f in pairs(character:GetChildren()) do
if f:IsA("BasePart") then
end
end
end
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = Blacklist
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local ray = Ray.new(unitRay.Origin, unitRay.Direction * 1000, raycastParams)
local hit, pos, normal = game:GetService("Workspace"):FindPartOnRayWithIgnoreList(ray, Blacklist)
local NewNormalX = normal.X
local NewNormalY = normal.Y
local NewNormalZ = normal.Z
local NewVector3 = Vector3.new(pos.X +0.5, pos.Y +0.5,pos.Z + 0.5)
local Value = 0
if NewNormalX < 0 then
Value = 1
NewVector3 = Vector3.new(pos.X -0.5, pos.Y,pos.Z)
end
if NewNormalY < 0 then
Value = 1
NewVector3 = Vector3.new(pos.X, pos.Y - 0.5,pos.Z)
end
if NewNormalZ < 0 then
Value = 1
NewVector3 = Vector3.new(pos.X, pos.Y,pos.Z -0.5)
end
PickedObject:SetPrimaryPartCFrame(CFrame.new(NewVector3,NewVector3+normal) * CFrame.Angles(-math.rad(90),math.rad(0),math.rad(0)))
local connection = PickedObject.DetectionArea.Touched:Connect(function() end)
local results = PickedObject.DetectionArea:GetTouchingParts()
connection:Disconnect()
for i,v in pairs(results) do
if v.Name == "DetectionArea" then
PickedObject.Highlight.Enabled = true
PickedObject.Highlight.FillColor = Color3.new(1, 0, 0)
IsPlacementValid = false
break
else
PickedObject.Highlight.Enabled = true
PickedObject.Highlight.FillColor = Color3.new(0, 1, 0)
ValidCFrame = PickedObject:GetPrimaryPartCFrame()
IsPlacementValid = true
end
end
end
end
end
end
end
end