-
What do you want to achieve?
When in build mode and selecting different buildings to make, I would like there to be a “preview” of the image (in viewport frame) on the button. -
What is the issue?
Rotation of the camera and position of both the object and the camera turn into a strange decimal far from what is intended.
P.S. the soil is pretty hard to see but trust it’s there in the first image lol
Desired goal: (I manually tweaked the settings after joining)
What happens:
local function setupBuildMode()
local smoothPlacementButton = placementGui:WaitForChild("SmoothPlacement")
local gridEnabledButton = placementGui:WaitForChild("GridEnabled")
smoothPlacementButton.MouseButton1Click:Connect(function()
if smoothPlacement then
smoothPlacement = false
smoothPlacementButton.Text = "Smooth placement: false"
else
smoothPlacement = true
smoothPlacementButton.Text = "Smooth placement: true"
end
end)
gridEnabledButton.MouseButton1Click:Connect(function()
if gridEnabled then
gridEnabled = false
gridEnabledButton.Text = "Grid enabled: false"
else
gridEnabled = true
gridEnabledButton.Text = "Grid enabled: true"
end
end)
local count = 0
local buildableButton = placementGui:WaitForChild("BuildableButton")
local buildableButtons = {}
for _, buildable in ipairs(buildables:GetChildren()) do
local clonedGui = buildableButton:Clone()
clonedGui.Parent = placementGui
clonedGui.TextLabel.Text = buildable.Name:gsub("([a-z])([A-Z])", "%1 %2")
clonedGui.Position = UDim2.new(
clonedGui.Position.X.Scale,
clonedGui.Position.X.Offset + (clonedGui.Size.X.Offset * 1.1) * count,
clonedGui.Position.Y.Scale,
clonedGui.Position.Y.Offset
)
task.wait(.1)
local viewPort = clonedGui:WaitForChild("Viewport")
local clonedBuildable = buildable:Clone()
clonedBuildable.Parent = viewPort
clonedBuildable.PrimaryPart.CFrame = CFrame.new(0,0,0)
local camera = Instance.new("Camera", viewPort)
camera.CFrame = CFrame.new(2, 3, 5)
camera.CFrame = CFrame.Angles(-30, 25, 0)
viewPort.CurrentCamera = camera
count = count + 1
buildableButtons[clonedGui] = buildable
end
return buildableButtons
end