Created
September 2, 2022 20:21
-
-
Save compscitwilight/a91cf0258d0013795b5660dbfda99f6e to your computer and use it in GitHub Desktop.
Client script for a Roblox build mode system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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