Advertisement
Guest User

Grass Handler

a guest
Feb 27th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. -- SERVICES
  2.  
  3. local Players = game:GetService("Players")
  4. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  5.  
  6. -- MODULES
  7.  
  8. local Modules = ReplicatedStorage.Modules
  9. local GetAsset = require(Modules.GetAsset)
  10.  
  11. -- REMOTES
  12.  
  13. local Remotes = ReplicatedStorage.Remotes
  14. local EnterGrass = Remotes.EnterGrass
  15.  
  16. -- PLAYER
  17.  
  18. local Player = Players.LocalPlayer
  19.  
  20. -- VARIABLES
  21.  
  22. local Ran = Random.new()
  23.  
  24. local EncounterAreas = workspace["Encounter Areas"]
  25. local Visuals = EncounterAreas.Visuals
  26.  
  27. -- CODE
  28.  
  29. function Start()
  30.     for _, Grass in pairs(EncounterAreas.Hitboxes:GetDescendants()) do
  31.         if Grass:IsA("BasePart") then
  32.             local Size = Grass.Size
  33.             local Position = Grass.CFrame
  34.             local Rows = Size.X/4 -- X
  35.             local Columns = Size.Z/4 -- Z
  36.             local Corner = Position * CFrame.new((-Size.X/2) - 2, 0, (-Size.Z/2) - 2)
  37.  
  38.             for Column = 1, Columns do
  39.                 for Row = 1, Rows do
  40.                     local Visual = GetAsset("Grass")
  41.                     Visual.CFrame = Corner * CFrame.new(Row * 4, 0, Column * 4)
  42.                     Visual.CFrame = Visual.CFrame * CFrame.Angles(0, Ran:NextNumber(0, 1), 0)
  43.                     Visual.Parent = Visuals
  44.                 end
  45.             end
  46.  
  47.             Grass.Touched:Connect(function(Hit)
  48.                 if Players:GetPlayerFromCharacter(Hit.Parent) == Player then
  49.                     if Hit.Name == "HumanoidRootPart" then
  50.                         EnterGrass:FireServer(Grass)
  51.                     end
  52.                 end
  53.             end)
  54.         end
  55.     end
  56. end
  57.  
  58. Start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement