Been trying to make this for a while. I think it’s pretty cool.
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local LocalPlayerCharacter = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local GetMouse = LocalPlayer:GetMouse()
local PreviousMouseTarget = GetMouse.Target
RunService.RenderStepped:Connect(function()
if PreviousMouseTarget ~= nil and GetMouse.Target == PreviousMouseTarget and not GetMouse.Target:FindFirstChildOfClass("SelectionBox") then
local SelectionBox = Instance.new("SelectionBox")
SelectionBox.Color3 = Color3.new(0, 0, 0)
SelectionBox.LineThickness = 0.01
SelectionBox.Adornee = GetMouse.Target
SelectionBox.Name = HttpService:GenerateGUID()
SelectionBox.Parent = GetMouse.Target
end
if PreviousMouseTarget ~= nil and GetMouse.Target ~= PreviousMouseTarget and PreviousMouseTarget:FindFirstChildOfClass("SelectionBox") then
PreviousMouseTarget:FindFirstChildOfClass("SelectionBox"):Destroy()
end
PreviousMouseTarget = GetMouse.Target
end)
UserInputService.InputBegan:Connect(function(InputBegan)
if InputBegan.UserInputType == Enum.UserInputType.MouseButton1 then
if GetMouse.Target then
GetMouse.Target:Destroy()
end
end
end)
UserInputService.InputEnded:Connect(function(InputEnded)
if InputEnded.UserInputType == Enum.UserInputType.MouseButton1 then
end
end)
UserInputService.InputBegan:Connect(function(InputBegan)
if InputBegan.UserInputType == Enum.UserInputType.MouseButton2 then
local RayNew = Ray.new(GetMouse.UnitRay.Origin, GetMouse.UnitRay.Direction * 100)
local Component, Position, SurfaceNormal, Material = workspace:FindPartOnRayWithIgnoreList(RayNew, {LocalPlayerCharacter})
if Component then
local Part = Instance.new("Part")
Part.CFrame = Component.CFrame + SurfaceNormal * 3
Part.Anchored = true
Part.Size = Vector3.new(3, 3, 3)
Part.Parent = workspace
print(SurfaceNormal)
end
end
end)
Rate.
If you want to test it I think you should use this!
Terrain Generator:
local WorldProportionX, WorldProportionY, WorldProportionZ = 100, 100, 100
local NoiseScale = 50
local Height = 25
local PartDimensions = 3
math.randomseed(tick())
local MathRandom = math.random()
for Number = -WorldProportionX, WorldProportionX do
for Number2 = -WorldProportionY, WorldProportionY do
for Number3 = -WorldProportionZ, WorldProportionZ do
local MathNoise = math.noise(Number2 / NoiseScale, Number3 / NoiseScale, MathRandom) * Height
local MathNoise2 = math.noise(Number / NoiseScale, Number3 / NoiseScale, MathRandom) * Height
local MathNoise3 = math.noise(Number / NoiseScale, Number2 / NoiseScale, MathRandom) * Height
local Density = MathNoise + MathNoise2 + MathNoise3 + Number2
if Density > 15 and Density < 20 then
local Part = Instance.new("Part")
Part.Anchored = true
Part.CFrame = CFrame.new(Number * PartDimensions, Number2 * PartDimensions, Number3 * PartDimensions)
Part.Size = Vector3.new(PartDimensions, PartDimensions, PartDimensions)
Part.Parent = workspace.Terrain
end
end
end
wait()
end
Non-clicking version!
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local LocalPlayerCharacter = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local GetMouse = LocalPlayer:GetMouse()
local PreviousMouseTarget = GetMouse.Target
RunService.RenderStepped:Connect(function()
if PreviousMouseTarget ~= nil and GetMouse.Target == PreviousMouseTarget and not GetMouse.Target:FindFirstChildOfClass("SelectionBox") then
local SelectionBox = Instance.new("SelectionBox")
SelectionBox.Color3 = Color3.new(0, 0, 0)
SelectionBox.LineThickness = 0.01
SelectionBox.Adornee = GetMouse.Target
SelectionBox.Name = HttpService:GenerateGUID()
SelectionBox.Parent = GetMouse.Target
end
if PreviousMouseTarget ~= nil and GetMouse.Target ~= PreviousMouseTarget and PreviousMouseTarget:FindFirstChildOfClass("SelectionBox") then
PreviousMouseTarget:FindFirstChildOfClass("SelectionBox"):Destroy()
end
PreviousMouseTarget = GetMouse.Target
end)
local MouseButton1Down = false
UserInputService.InputBegan:Connect(function(InputBegan)
if InputBegan.UserInputType == Enum.UserInputType.MouseButton1 then
if GetMouse.Target then
MouseButton1Down = true
while wait() and MouseButton1Down do
GetMouse.Target:Destroy()
end
end
end
end)
UserInputService.InputEnded:Connect(function(InputEnded)
if InputEnded.UserInputType == Enum.UserInputType.MouseButton1 then
MouseButton1Down = false
end
end)
local MouseButton2Down = false
UserInputService.InputBegan:Connect(function(InputBegan)
if InputBegan.UserInputType == Enum.UserInputType.MouseButton2 then
MouseButton2Down = true
while wait() and MouseButton2Down do
local RayNew = Ray.new(GetMouse.UnitRay.Origin, GetMouse.UnitRay.Direction * 100)
local Component, Position, SurfaceNormal, Material = workspace:FindPartOnRayWithIgnoreList(RayNew, {LocalPlayerCharacter})
if Component then
local Part = Instance.new("Part")
Part.CFrame = Component.CFrame + SurfaceNormal * 3
Part.Anchored = true
Part.Size = Vector3.new(3, 3, 3)
Part.Parent = workspace
print(SurfaceNormal)
end
end
end
end)
UserInputService.InputEnded:Connect(function(InputEnded)
if InputEnded.UserInputType == Enum.UserInputType.MouseButton2 then
MouseButton2Down = false
end
end)