Idk where to post this so I post it here, so basically I made a building mode game
So when you place objects, its getting random orientation, I mean the server side script will clone objects just like its made on baseplate and then will spawn, but its spawning so weird that some objects are spawned upside down and some are spawned tilted, how do i fix ths
local currentitem = nil
local context = game:GetService("ContextActionService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local spawns = 0
local function changeselection(actionname,inputstate)
if actionname == "MoveSelection" then
local mousecframe = mouse.Hit.Position
if currentitem ~= nil then
if currentitem:IsA("BasePart") then
currentitem.Anchored = true
currentitem.CanCollide = false
currentitem.Transparency = 0.5
currentitem.Position = Vector3.new(math.ceil(mousecframe.X/currentitem.Size.X)*currentitem.Size.X,currentitem.Size.Y/2,math.ceil(mousecframe.Z/currentitem.Size.Z)*currentitem.Size.Z)
else
currentitem:SetPrimaryPartCFrame(CFrame.new(Vector3.new(mousecframe.X,0.5,mousecframe.Z)))
currentitem.PrimaryPart.Anchored = true
end
end
end
end
local function rotateblock(actionname,inputstate)
if currentitem ~= nil and inputstate == Enum.UserInputState.Begin then
if currentitem:IsA("Model") then
currentitem.PrimaryPart.Orientation += Vector3.new(0,5,0)
else
currentitem.Orientation += Vector3.new(0,5,0)
end
end
end
mouse.Button1Down:Connect(function()
local tabletosend = {
["ObjectName"] = "",
["CFrame"] = {
["x"] = 0,
["y"] = 0,
["z"] = 0
},
["Position"] = mouse.Hit,
["Orientation"] = 0
}
if currentitem ~= nil and currentitem.Parent == workspace then
if currentitem:IsA("Model") then
tabletosend["CFrame"]["x"] = currentitem.PrimaryPart.CFrame.Position.X
tabletosend["CFrame"]["y"] = currentitem.PrimaryPart.CFrame.Position.Y
tabletosend["CFrame"]["z"] = currentitem.PrimaryPart.CFrame.Position.Z
tabletosend["ObjectName"] = currentitem.Name
else
tabletosend["CFrame"]["x"] = currentitem.CFrame.Position.X
tabletosend["CFrame"]["y"] = currentitem.CFrame.Position.Y
tabletosend["CFrame"]["z"] = currentitem.CFrame.Position.Z
tabletosend["ObjectName"] = currentitem.Name
tabletosend["Orientation"] = currentitem.Orientation
end
game.ReplicatedStorage.PlaceBlockEvent:FireServer(tabletosend)
end
end)
script.Parent.MouseButton1Down:Connect(function()
context:BindAction("MoveSelection",changeselection,false,Enum.UserInputType.MouseMovement)
context:BindAction("RotatePart",rotateblock,true,Enum.KeyCode.R)
script.Parent.Parent.ScrollingFrame:TweenPosition(UDim2.new(0, 0,0.798, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,1)
end)
for i,v in pairs(script.Parent.Parent.ScrollingFrame:GetChildren()) do -- selecting local building
if v:IsA("Frame") then
v.TextButton.MouseButton1Down:Connect(function()
if v.Name == "Spawn" then
if spawns <= 1 then
local clone = game.ReplicatedStorage.Items:FindFirstChild(v.Name):Clone()
clone.Parent = workspace
if currentitem ~= nil then
currentitem:Destroy()
end
currentitem = clone
else
v.TextButton.Text = "Max limit reached"
end
else
local clone = game.ReplicatedStorage.Items:FindFirstChild(v.Name):Clone()
clone.Parent = workspace
if currentitem ~= nil then
currentitem:Destroy()
end
currentitem = clone
end
end)
end
end
Server-side script:
local objects = game.ReplicatedStorage.Items
game.ReplicatedStorage.PlaceBlockEvent.OnServerEvent:Connect(function(plr,tabletobuild)
print(tabletobuild)
if objects:FindFirstChild(tabletobuild["ObjectName"]):IsA("Model") then
local clone = objects[tabletobuild["ObjectName"]]:Clone()
clone.Parent = workspace
clone.Anchored = true
clone.PrimaryPart.CFrame = tabletobuild["Position"]
else
local clone = objects:FindFirstChild(tabletobuild["ObjectName"]):Clone()
clone.Parent = workspace
clone.CFrame = tabletobuild["Position"]
clone.Anchored = true
clone.Orientation = tabletobuild["Orientation"]
clone.Position = Vector3.new(tabletobuild["CFrame"]["x"],clone.Size.Y/2,tabletobuild["CFrame"]["z"])
end
end)
Try using CFrame.new for the orientation instead of Vector3.new, this is probably because the parts are rotated in world space, and since it’s a model, (method 2) not all parts are at a equal state, so use a primarypart.