Hello,
Going to get straight to the point, I made this placement system a couple of days ago, and it works perfectly, unless, it flips my items in the X axis everytime I try to place it down, or just to preview where it is going to be placed in.
Here’s how the code flips it:
While it was supposed to place like this, horizontally:
Code:
local CS = game:GetService("CollectionService")
local TS = game:GetService("TweenService")
local RS = game:GetService("ReplicatedStorage")
local placeObject = RS.Events.Events:FindFirstChild("PlaceItem")
local TI = TweenInfo.new(0.001)
local objects = RS:FindFirstChild("Placables")
local temporaryObjects = workspace:FindFirstChild("PlacementFolder"):FindFirstChild("TemporaryObjects")
local plr = game.Players.LocalPlayer
local moveConnection
local mouse = plr:GetMouse()
local char = plr.Character or plr.CharacterAdded:Wait()
local currentObject = nil
local debounce = false
local function move()
local posX = math.floor(mouse.Hit.X)
local posY = math.floor(mouse.Hit.Y + currentObject.PrimaryPart.Size.Y / 2)
local posZ = math.floor(mouse.Hit.Z)
local orientationY = currentObject.PrimaryPart.Orientation.Y
debounce = true
local Tween = TS:Create(currentObject.PrimaryPart, TI,
{CFrame = CFrame.new(posX, posY, posZ) * CFrame.Angles(0, math.rad(orientationY), 0)})
Tween:Play()
Tween.Completed:Wait()
debounce = false
end
local function weld()
debounce = true
for objs, obj in pairs(currentObject:GetDescendants()) do
if obj:IsA("BasePart") and obj ~= currentObject.PrimaryPart then
local weldConstraint = Instance.new("WeldConstraint")
weldConstraint.Part0 = obj
weldConstraint.Part1 = currentObject.PrimaryPart
weldConstraint.Parent = obj
obj.Anchored = false
obj.CanCollide = false
end
end
mouse.TargetFilter = currentObject
debounce = false
return
end
local function place(tool, plr)
placeObject:FireServer(currentObject.Name, currentObject.PrimaryPart.Position.X, currentObject.PrimaryPart.Position.Z, currentObject.PrimaryPart.Position.Y)
char.Humanoid:UnequipTools()
temporaryObjects:ClearAllChildren()
tool.Count.Value -= 1
if tool.Count.Value <= 0 then
tool:Destroy()
end
plr.PlayerGui.Inventory.Enabled = true
require(game.ReplicatedStorage.Modules.ChangeLevel).AddExp(plr, 2)
end
tool.Equipped:Connect(function()
plr.PlayerGui.Inventory.Enabled = false
game.TweenService:Create(plr.PlayerGui.MainUI.MobileBuilding, TweenInfo.new(.25), {Position = UDim2.new(0,0,.9,0)}):Play()
for i, v in tool.Handle:GetDescendants() do
if v:IsA("MeshPart") or v:IsA("BasePart") or v:IsA("Texture") then
v.Transparency = 1
end
end
tool.hammer.Transparency = 1
local foundObject = objects:FindFirstChild(tool.Name)
if foundObject then
currentObject = foundObject:Clone()
plr.PlayerGui.MainUI.MobileBuilding.place.obj.Value = currentObject
currentObject.Parent = temporaryObjects
weld()
moveConnection = mouse.Move:Connect(move)
move()
tool.Activated:Connect(function()
if moveConnection ~= nil then
moveConnection:Disconnect()
moveConnection = nil
end
plr.PlayerGui.MainUI.MobileBuilding.place.obj.Value = nil
place(tool, plr)
end)
plr.PlayerGui.MainUI.MobileBuilding.place.MouseButton1Click:Connect(function()
if plr.PlayerGui.MainUI.MobileBuilding.place.obj.Value == currentObject then
plr.PlayerGui.MainUI.MobileBuilding.place.obj.Value = nil
place(tool, plr)
end
end)
end
end)
tool.Unequipped:Connect(function()
if moveConnection ~= nil then
moveConnection:Disconnect()
moveConnection = nil
game.TweenService:Create(plr.PlayerGui.MainUI.MobileBuilding, TweenInfo.new(.25), {Position = UDim2.new(0,0,1.05,0)}):Play()
temporaryObjects:ClearAllChildren()
task.wait(.28)
plr.PlayerGui.Inventory.Enabled = true
end
end)
Thanks.