Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.76 KB | None | 0 0
  1. --GG's Snow
  2. local Players = game:GetService("Players")
  3. Players.LocalPlayer.CameraMode = "Classic"
  4.  
  5. local Configuration = {
  6.         SnowModelName     = "SnowModel";
  7.         SnowColor         = Vector3.new(1, 1, 1);
  8.         SmallestFlakeSize = 8; -- Divided by 100
  9.         LargestFlakeSize  = 15;
  10.         MaxMoveX          = 5; -- Divided by 100
  11.         MinMoveX          = -5;
  12.         MaxMoveY          = 5;
  13.         MinMoveY          = -10;
  14.         MaxMoveZ          = 5;
  15.         MinMoveZ          = -5;
  16.         CyclesPerLifeMax  = 4;
  17.         CyclesPerLifeMin  = 2;
  18.         CycleLife         = 20;
  19.         MaxTransparency   = 0.3;
  20.         RangeX = 4;
  21.         RangeY = 4;
  22.         RangeZ = 4;
  23. }
  24.  
  25. local function GetSnowModel()
  26.         local Model = workspace.CurrentCamera:FindFirstChild(Configuration.SnowModelName)
  27.         if not Model then
  28.                 Model = Instance.new("Model", workspace.CurrentCamera)
  29.                 Model.Name = Configuration.SnowModelName
  30.                 Model.Archivable = false;
  31.         end
  32.         return Model
  33. end
  34.  
  35. local function GetSnowflakeMovement()
  36.         return Vector3.new(
  37.                 math.random(Configuration.MinMoveX, Configuration.MaxMoveX)/100,
  38.                 math.random(Configuration.MinMoveY, Configuration.MaxMoveY)/100,
  39.                 math.random(Configuration.MinMoveZ, Configuration.MaxMoveZ)/100
  40.         )
  41. end
  42.  
  43. local function GetRandomSnowflakePosition(LastValidPlace)
  44.         return CFrame.new(LastValidPlace + Vector3.new(
  45.                         math.random(-Configuration.RangeX, Configuration.RangeX),
  46.                         math.random(-3, Configuration.RangeY),
  47.                         math.random(-Configuration.RangeZ, Configuration.RangeZ)
  48.                 ) + Players.LocalPlayer.Character.Torso.CFrame.lookVector * 2)
  49. end
  50.  
  51. local SnowflakeQueue = {}
  52.  
  53. local function UpdateQueue()
  54.         local HalfLife = Configuration.CycleLife;
  55.         local MaxTransparency = Configuration.MaxTransparency
  56.         for Index, SnowFlake in pairs(SnowflakeQueue) do
  57.                 local CycleTick = SnowFlake.CycleTick
  58.                 local Flake = SnowFlake.Flake
  59.                 if SnowFlake.Mode == 2 then
  60.                         SnowFlake.CyclesLeft = SnowFlake.CyclesLeft - 1
  61.                         if SnowFlake.CyclesLeft <= 0 then
  62.                                 SnowFlake.Flake:Destroy()
  63.                                 table.remove(SnowflakeQueue, Index)
  64.                         else
  65.                                 SnowFlake.CycleTick = Configuration.CycleLife
  66.                                 SnowFlake.Mode = 0
  67.                         end
  68.                 elseif SnowFlake.Mode == 0 then
  69.                         Flake.Transparency = (CycleTick/HalfLife)* MaxTransparency + (MaxTransparency)
  70.                         Flake.CFrame = Flake.CFrame + SnowFlake.MoveRate
  71.                         SnowFlake.CycleTick = CycleTick - 1
  72.                         if SnowFlake.CycleTick <= 0 then
  73.                                 SnowFlake.Mode = 1
  74.                         end
  75.                 elseif SnowFlake.Mode == 1 then
  76.                         Flake.Transparency = (CycleTick/HalfLife)*MaxTransparency + (MaxTransparency)
  77.                         Flake.CFrame = Flake.CFrame + SnowFlake.MoveRate
  78.                         SnowFlake.CycleTick = CycleTick + 1
  79.                         if SnowFlake.CycleTick >= HalfLife then
  80.                                 SnowFlake.Mode = 2
  81.                         end
  82.                 end
  83.         end
  84. end
  85.  
  86. local function MakeSnowFlake(Parent, InitialCFrame)
  87.         local FlakeSize = math.random(Configuration.SmallestFlakeSize, Configuration.LargestFlakeSize)/100
  88.  
  89.         local Flake         = Instance.new("Part", Parent)
  90.         Flake.Anchored      = true;
  91.         Flake.CanCollide    = false;
  92.         Flake.FormFactor    = "Custom";
  93.         Flake.Size          = Vector3.new(1, 1, 1)
  94.         Flake.Name          = "SnowFlake";
  95.         Flake.BottomSurface = "Smooth";
  96.         Flake.CFrame        = InitialCFrame
  97.         Flake.Transparency  = 1;
  98.  
  99.         local Mesh = Instance.new("SpecialMesh", Flake)
  100.         Mesh.MeshType    = "FileMesh"
  101.         Mesh.MeshId      = "http://www.roblox.com/asset/?id=1185246"
  102.         Mesh.TextureId   = "http://www.roblox.com/asset/?id=1361097"
  103.         Mesh.VertexColor = Configuration.SnowColor;
  104.         Mesh.Scale       = Vector3.new(FlakeSize, FlakeSize, FlakeSize)
  105.  
  106.         local SnowFlake = {}
  107.         SnowFlake.Flake = Flake;
  108.         SnowFlake.CycleTick = Configuration.CycleLife
  109.         SnowFlake.CyclesLeft = math.random(Configuration.CyclesPerLifeMin, Configuration.CyclesPerLifeMax)
  110.         SnowFlake.MoveRate = GetSnowflakeMovement()
  111.         SnowFlake.Mode = 0
  112.         table.insert(SnowflakeQueue, SnowFlake)
  113. end
  114.  
  115. local SnowModel = GetSnowModel()
  116. SnowModel:ClearAllChildren()
  117.  
  118. while not Players.LocalPlayer.Character do wait(0) end
  119.  
  120. local LastValidPlace = Players.LocalPlayer.Character.Torso.Position
  121. repeat wait() until Players.LocalPlayer.Character ~= nil
  122. while (Players.LocalPlayer.Parent and Players.LocalPlayer.Character) do    -- This is where I'd guess the problem is.
  123.         if Players.LocalPlayer.Character:FindFirstChild("Torso") then
  124.                 local Torso = Players.LocalPlayer.Character.Torso
  125.                 local NewRay = Ray.new(Torso.Position + Vector3.new(0, 3, 0), Vector3.new(0, 100, 0))
  126.                 local Hit, Position = workspace:FindPartOnRay(NewRay, SnowModel, true)
  127.                 if not Hit then
  128.                         LastValidPlace = Torso.Position
  129.                 --else
  130.                         --print("Inside")
  131.                 end
  132.                 MakeSnowFlake(SnowModel, GetRandomSnowflakePosition(LastValidPlace))
  133.         end
  134.         spawn(UpdateQueue)
  135.         wait()
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement