I have a building system I’m messing around with and it has multiple blocks such as bricks, planks, and stairs. The problem comes in with the stairs. I want the player to be able to rotate the stairs with the camera. The same way that in islands (remember that game people used to like?) you could rotate the camera and the thing you were placing would rotate with it, but only in multiples of 90.
For example, you can see in this video when I move the camera, the sapling rotates with it.
Here’s the code for placing the stairs so far! I think most of it doesn’t matter but still.
Client code (very messy i know)
local tool = script.Parent
local handle = tool:FindFirstChild("Handle")
local mouse = game.Players.LocalPlayer:GetMouse()
local rs = game:GetService("RunService")
local isEquipped = false
-- Function to round numbers used for snap to grid
function round(n)
return math.floor(n * 1) / 1
end
local x
local y
local z
script.Parent.Equipped:Connect(function()
isEquipped = true
local placePreview = handle:Clone() -- Create a copy of the tool (what's placed) that is used to preview where it's placed'
placePreview.Transparency = 0.5
placePreview.CanCollide = false
placePreview.Name = "Preview"
placePreview.Parent = workspace
x = round(mouse.Hit.Position.X)
y = 1
z = round(mouse.Hit.Position.Z)
placePreview.Position = Vector3.new(x, y, z)
end)
rs.RenderStepped:Connect(function() -- Every frame update the position of the preview
local previewToMove = game.Workspace:FindFirstChild("Preview")
if previewToMove and game.Players:GetPlayerFromCharacter(script.Parent.Parent) then
x = round(mouse.Hit.Position.X)
y = 1
z = round(mouse.Hit.Position.Z)
previewToMove.Position = Vector3.new(x, y, z)
end
end)
-- Clean up the preview when you're not holding it
script.Parent.Unequipped:Connect(function()
isEquipped = false
local previewToDestroy = game.Workspace:FindFirstChild("Preview")
if previewToDestroy then
previewToDestroy:Destroy()
end
end)
-- Run the function to place it every time you click
mouse.Button1Down:Connect(function()
if not isEquipped then return end
game.ReplicatedStorage.Place:FireServer(handle, Vector3.new(x, y, z), Vector3.new(), true, true)
-- Arguments for server in order: Part to place, position, orientation, CanCollide, Anchored
end)
Any ideas?