like a blue line falling in a vertical way or in a straight way and loops again
Never thought about this! Good idea! I guess you can make rain by first creating 2 models:
1) The rain model (just a very very tiny and straight blue brick with cylinder mesh, like you said):
2) A big transparent brick in the sky covering the entire zone where it rains, let's call it CLOUD_SPAWN.
After that you can get the Vec3 angles of the CLOUD_SPAWN like this:
A######## ######### ########B
We can define the X and Z in this way:
--Remember to set CanCollide to false and Transparency to 1! local CLOUD_SPAWN = game.Workspace.CloudSpawn local xCoord_START = CLOUD_SPAWN.Position.X local xCoord_FINISH = xCoord_START + CLOUD_SPAWN.Size.X local zCoord_START = CLOUD_SPAWN.Position.Z local zCoord_FINISH = zCoord_START + CLOUD_SPAWN.Size.Z
Now we need to do the spawning code:
function spawnRainBrick() local randomXCoord = math.random(xCoord_START, xCoord_FINISH) local randomZCoord = math.random(zCoord_START, zCoord_FINISH) local rainBrick = game.Lighting.RainBrick:Clone() rainBrick.Parent = game.Workspace rainBrick.Position = Vector3.new(randomXCoord, CLOUD_SPAWN.Position.Y, randomZCoord) end
After this we need to make a loop that check if your rain event is active, let's call it eventRain.
-- This function will check if in the game is raining each second function rainUpdate() --I suppose to have a model called "Events" wich contains every event value as a BoolValue while game.Workspace.Events.eventRain.Value == true do spawnRainBrick() wait(0.3) end end
This will spawn a rain brick each 300ms (3 ds (deciseconds)) But what if the game lags? If the game lags it's because there are a lot of rain bricks, we need to destroy them when they touch something =), this is the code:
function destroyRainBrick(part) part:Destroy() end
And then we need to call it in another function or just outside everything, I recommend to do outside everything (so inside the script's body)
for _, workspacePart in pairs(game.Workspace:GetChildren()) do -- The rain brick model need to be named as "RainBrick" if workspacePart.Name == "RainBrick" then workspacePart.Touched:Connect(destroyRainBrick) end end
FINAL CODE:
--Remember to set CanCollide to false and Transparency to 1! local CLOUD_SPAWN = game.Workspace.CloudSpawn local xCoord_START = CLOUD_SPAWN.Position.X local xCoord_FINISH = xCoord_START + CLOUD_SPAWN.Size.X local zCoord_START = CLOUD_SPAWN.Position.Z local zCoord_FINISH = zCoord_START + CLOUD_SPAWN.Size.Z function spawnRainBrick() local randomXCoord = math.random(xCoord_START, xCoord_FINISH) local randomZCoord = math.random(zCoord_START, zCoord_FINISH) local rainBrick = game.Lighting.RainBrick:Clone() rainBrick.Parent = game.Workspace rainBrick.Position = Vector3.new(randomXCoord, CLOUD_SPAWN.Position.Y, randomZCoord) end -- This function will check if in the game is raining each second function rainUpdate() --I suppose to have a model called "Events" wich contains every event value as a BoolValue while game.Workspace.Events.eventRain.Value == true do spawnRainBrick() wait(0.3) end end function destroyRainBrick(part) part:Destroy() end for _, workspacePart in pairs(game.Workspace:GetChildren()) do -- The rain brick model need to be named as "RainBrick" if workspacePart.Name == "RainBrick" then workspacePart.Touched:Connect(destroyRainBrick) end end
This is a SIMILIAR code, I hope it works because... WARNING: The code is not tested and may not works, if it doesn't then send me a PM with the problems given in the output! Bye!
Before we begin, Insert a brick into the workspace and color it and size it, Etc. (Name it: Drop)
while true do wait() local rain = game.Workspace.Drop:Clone() rain.Parent = game.Workspace rain.Position = Vector3.new(math.random(-500, 500), 100, math.random(-500, 500)) rain.Anchored = false wait(2) rain:remove() end