Skip to content

Instantly share code, notes, and snippets.

@compscitwilight
Created September 2, 2022 20:21
Show Gist options
  • Save compscitwilight/a91cf0258d0013795b5660dbfda99f6e to your computer and use it in GitHub Desktop.
Save compscitwilight/a91cf0258d0013795b5660dbfda99f6e to your computer and use it in GitHub Desktop.
Client script for a Roblox build mode system
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Building = false
local Mouse = Players.LocalPlayer:GetMouse()
local Brick = script.Part
local function RoundVector3(vector: Vector3)
return Vector3.new(
math.floor(vector.X),
math.floor(vector.Y),
math.floor(vector.Z)
)
end
UserInputService.InputBegan:Connect(function(key, gp)
if gp then return end
if key.KeyCode == Enum.KeyCode.B then
Building = not Building
if Building then
Brick.Parent = workspace.Building
return
end
Brick.Parent = script
return
end
end)
RunService.RenderStepped:Connect(function()
if not Building then return end
local target = Mouse.Target
if not target then return end
local position = RoundVector3(Mouse.Hit.Position)
Brick.Transparency = .5
Brick.Position = RoundVector3(position)
print(position)
end)
Mouse.Button1Down:Connect(function()
if not Building then return end
local target = Mouse.Target
if not target then return end
local clone = Brick:Clone()
clone.Parent = workspace
clone.Transparency = 0
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment