Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Module = require(game.ReplicatedStorage.Modules.Triangle)
- local UIS = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local Player = game.Players.LocalPlayer
- local Character = Player.Character or Player.CharacterAdded:Wait()
- local Mouse = Player:GetMouse()
- local Counter = 1
- local Grid = 4
- local Toggle = false
- local PointA = script.Point:Clone()
- local PointB = script.Point:Clone()
- local PointC = script.Point:Clone()
- local PosA
- local PosB
- local LRA
- local LRB
- local ta, tb
- local FN = 1
- function Round(Num, To)
- return math.floor(Num / To + 0.5) * To
- end
- local function DrawTriangle(A, B, C)
- ta, tb = require(game.ReplicatedStorage.Modules.Triangle)(A, B, C, workspace, ta, tb, FN)
- end
- RunService.RenderStepped:Connect(function()
- if Toggle then
- if Counter == 1 then
- PointA.Parent = workspace
- PosA = Vector3.new(Round(Mouse.Hit.p.X, Grid), 0, Round(Mouse.Hit.p.Z, Grid))
- PointA.CFrame = CFrame.new(PosA)
- PointA.Orientation = Vector3.new(0, 90, -90)
- elseif Counter == 2 then
- PointB.Parent = workspace
- PosB = Vector3.new(Round(Mouse.Hit.p.X, Grid), 0, Round(Mouse.Hit.p.Z, Grid))
- PointB.CFrame = CFrame.new(PosB)
- PointB.Orientation = Vector3.new(0, 90, -90)
- if LRA then
- LRA:Destroy()
- LRA = nil
- end
- local Mag = (PosA - PosB).magnitude
- local ray = Ray.new(PosA, (PosA - PosB).unit * Mag)
- local part, position = workspace:FindPartOnRay(ray, workspace.Baseplate, false, true)
- local beam = Instance.new("Part", workspace)
- beam.BrickColor = BrickColor.new("Bright yellow")
- beam.FormFactor = "Custom"
- beam.Material = "Neon"
- beam.Transparency = 0.25
- beam.Anchored = true
- beam.Locked = true
- beam.CanCollide = false
- local distance = (PosA - position).magnitude
- beam.Size = Vector3.new(0.3, 1, distance)
- beam.CFrame = CFrame.new(PosA, position) * CFrame.new(0, 0, distance / 2)
- LRA = beam
- elseif Counter == 3 then
- PointC.Parent = workspace
- PosB = Vector3.new(Round(Mouse.Hit.p.X, Grid), 0, Round(Mouse.Hit.p.Z, Grid))
- PointC.CFrame = CFrame.new(PosB)
- PointC.Orientation = Vector3.new(0, 90, -90)
- if LRB then
- LRB:Destroy()
- LRB = nil
- end
- local Mag = (PosA - PosB).magnitude
- local ray = Ray.new(PosA, (PosA - PosB).unit * Mag)
- local part, position = workspace:FindPartOnRay(ray, workspace.Baseplate, false, true)
- local beam = Instance.new("Part", workspace)
- beam.BrickColor = BrickColor.new("Bright yellow")
- beam.FormFactor = "Custom"
- beam.Material = "Neon"
- beam.Transparency = 0.25
- beam.Anchored = true
- beam.Locked = true
- beam.CanCollide = false
- local distance = (PosA - position).magnitude
- beam.Size = Vector3.new(0.3, 1, distance)
- beam.CFrame = CFrame.new(PosA, position) * CFrame.new(0, 0, distance / 2)
- LRB = beam
- end
- end
- end)
- Mouse.Button1Down:Connect(function()
- if Toggle then
- if Counter == 1 then
- Counter = 2
- elseif Counter == 2 then
- Counter = 3
- PosA = Vector3.new(Round(Mouse.Hit.p.X, Grid), 0, Round(Mouse.Hit.p.Z, Grid))
- elseif Counter == 3 then
- Counter = 1
- local Mag = (PosA - PosB).magnitude
- DrawTriangle(PointA.Position, PointB.Position, PointC.Position)
- for _, W in pairs(workspace:WaitForChild("Floor" .. FN):GetChildren()) do
- W:Clone().Parent = W.Parent
- end
- LRA:Destroy()
- LRB:Destroy()
- PointA:Destroy()
- PointB:Destroy()
- PointC:Destroy()
- PointA = script.Point:Clone()
- PointB = script.Point:Clone()
- PointC = script.Point:Clone()
- FN = FN + 1
- end
- end
- end)
- script.Parent.MouseButton1Click:Connect(function()
- Toggle = true
- script.Parent.Parent.Parent:TweenPosition(UDim2.new(.5,0,1.5,2), Enum.EasingDirection.InOut, Enum.EasingStyle.Quart, .1)
- script.Parent.Parent.Parent.Parent.Parent.Button.Visible = false
- end)
- UIS.InputBegan:Connect(function(Input)
- if Input.KeyCode == Enum.KeyCode.X then
- script.Parent.Parent.Parent:TweenPosition(UDim2.new(.5,0,.5,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quart, .1)
- script.Parent.Parent.Parent.Parent.Parent.Button.Visible = true
- LRA:Destroy()
- PointA:Destroy()
- PointB:Destroy()
- PointA = script.Point:Clone()
- PointB = script.Point:Clone()
- Toggle = false
- Counter = 1
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement