Advertisement
Ariya1234gamer

Floor System

Mar 31st, 2020
2,393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.32 KB | None | 0 0
  1. local Module = require(game.ReplicatedStorage.Modules.Triangle)
  2.  
  3. local UIS = game:GetService("UserInputService")
  4. local RunService = game:GetService("RunService")
  5.  
  6. local Player = game.Players.LocalPlayer
  7. local Character = Player.Character or Player.CharacterAdded:Wait()
  8. local Mouse = Player:GetMouse()
  9.  
  10. local Counter = 1
  11. local Grid = 4
  12. local Toggle = false
  13.  
  14. local PointA = script.Point:Clone()
  15. local PointB = script.Point:Clone()
  16. local PointC = script.Point:Clone()
  17.  
  18. local PosA
  19. local PosB
  20. local LRA
  21. local LRB
  22. local ta, tb
  23. local FN = 1
  24.  
  25. function Round(Num, To)
  26.     return math.floor(Num / To + 0.5) * To
  27. end
  28.  
  29. local function DrawTriangle(A, B, C)
  30.     ta, tb = require(game.ReplicatedStorage.Modules.Triangle)(A, B, C, workspace, ta, tb, FN)
  31. end
  32.  
  33. RunService.RenderStepped:Connect(function()
  34.     if Toggle then
  35.         if Counter == 1 then
  36.             PointA.Parent = workspace
  37.             PosA = Vector3.new(Round(Mouse.Hit.p.X, Grid), 0, Round(Mouse.Hit.p.Z, Grid))
  38.             PointA.CFrame = CFrame.new(PosA)
  39.             PointA.Orientation = Vector3.new(0, 90, -90)
  40.         elseif Counter == 2 then
  41.             PointB.Parent = workspace
  42.             PosB = Vector3.new(Round(Mouse.Hit.p.X, Grid), 0, Round(Mouse.Hit.p.Z, Grid))
  43.             PointB.CFrame = CFrame.new(PosB)
  44.             PointB.Orientation = Vector3.new(0, 90, -90)
  45.            
  46.             if LRA then
  47.                 LRA:Destroy()
  48.                 LRA = nil
  49.             end
  50.            
  51.             local Mag = (PosA - PosB).magnitude
  52.            
  53.             local ray = Ray.new(PosA, (PosA - PosB).unit * Mag)
  54.             local part, position = workspace:FindPartOnRay(ray, workspace.Baseplate, false, true)
  55.            
  56.             local beam = Instance.new("Part", workspace)
  57.             beam.BrickColor = BrickColor.new("Bright yellow")
  58.             beam.FormFactor = "Custom"
  59.             beam.Material = "Neon"
  60.             beam.Transparency = 0.25
  61.             beam.Anchored = true
  62.             beam.Locked = true
  63.             beam.CanCollide = false
  64.            
  65.             local distance = (PosA - position).magnitude
  66.             beam.Size = Vector3.new(0.3, 1, distance)
  67.             beam.CFrame = CFrame.new(PosA, position) * CFrame.new(0, 0, distance / 2)
  68.             LRA = beam
  69.         elseif Counter == 3 then
  70.             PointC.Parent = workspace
  71.             PosB = Vector3.new(Round(Mouse.Hit.p.X, Grid), 0, Round(Mouse.Hit.p.Z, Grid))
  72.             PointC.CFrame = CFrame.new(PosB)
  73.             PointC.Orientation = Vector3.new(0, 90, -90)
  74.            
  75.             if LRB then
  76.                 LRB:Destroy()
  77.                 LRB = nil
  78.             end
  79.            
  80.             local Mag = (PosA - PosB).magnitude
  81.            
  82.             local ray = Ray.new(PosA, (PosA - PosB).unit * Mag)
  83.             local part, position = workspace:FindPartOnRay(ray, workspace.Baseplate, false, true)
  84.            
  85.             local beam = Instance.new("Part", workspace)
  86.             beam.BrickColor = BrickColor.new("Bright yellow")
  87.             beam.FormFactor = "Custom"
  88.             beam.Material = "Neon"
  89.             beam.Transparency = 0.25
  90.             beam.Anchored = true
  91.             beam.Locked = true
  92.             beam.CanCollide = false
  93.            
  94.             local distance = (PosA - position).magnitude
  95.             beam.Size = Vector3.new(0.3, 1, distance)
  96.             beam.CFrame = CFrame.new(PosA, position) * CFrame.new(0, 0, distance / 2)
  97.             LRB = beam
  98.         end
  99.     end
  100. end)
  101.  
  102. Mouse.Button1Down:Connect(function()
  103.     if Toggle then
  104.         if Counter == 1 then
  105.             Counter = 2
  106.         elseif Counter == 2 then
  107.             Counter = 3
  108.             PosA = Vector3.new(Round(Mouse.Hit.p.X, Grid), 0, Round(Mouse.Hit.p.Z, Grid))
  109.         elseif Counter == 3 then
  110.             Counter = 1
  111.            
  112.             local Mag = (PosA - PosB).magnitude
  113.            
  114.             DrawTriangle(PointA.Position, PointB.Position, PointC.Position)
  115.             for _, W in pairs(workspace:WaitForChild("Floor" .. FN):GetChildren()) do
  116.                 W:Clone().Parent = W.Parent
  117.             end
  118.            
  119.             LRA:Destroy()
  120.             LRB:Destroy()
  121.             PointA:Destroy()
  122.             PointB:Destroy()
  123.             PointC:Destroy()
  124.             PointA = script.Point:Clone()
  125.             PointB = script.Point:Clone()
  126.             PointC = script.Point:Clone()
  127.             FN = FN + 1
  128.         end
  129.     end
  130. end)
  131.  
  132. script.Parent.MouseButton1Click:Connect(function()
  133.     Toggle = true
  134.     script.Parent.Parent.Parent:TweenPosition(UDim2.new(.5,0,1.5,2), Enum.EasingDirection.InOut, Enum.EasingStyle.Quart, .1)
  135.     script.Parent.Parent.Parent.Parent.Parent.Button.Visible = false
  136. end)
  137.  
  138. UIS.InputBegan:Connect(function(Input)
  139.     if Input.KeyCode == Enum.KeyCode.X then
  140.         script.Parent.Parent.Parent:TweenPosition(UDim2.new(.5,0,.5,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quart, .1)
  141.         script.Parent.Parent.Parent.Parent.Parent.Button.Visible = true
  142.         LRA:Destroy()
  143.         PointA:Destroy()
  144.         PointB:Destroy()
  145.         PointA = script.Point:Clone()
  146.         PointB = script.Point:Clone()
  147.         Toggle = false
  148.         Counter = 1
  149.        
  150.     end
  151. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement