Hey guys. I’m trying to make rain that comes out of a cloud. I tried to script the raindrops so that when the raindrop touches something, it will delete. However, the raindrops keep getting deleted in midair. I’ve run tests and the problem is happening within the script. I believe the problem is that when one raindrop really touches the ground, another raindrop gets deleted instead. But then again I might be wrong. Please help ![:disappointed_relieved: :disappointed_relieved:](https://doy2mn9upadnk.cloudfront.net/images/emoji/twitter/disappointed_relieved.png?v=12)
Image of the problem(video takes too long to make)
Here is the code
local cloud = script.Parent
while true do
local raindrop = Instance.new("Part")
local mesh = Instance.new("SpecialMesh")
raindrop.CanCollide = false
raindrop.CanTouch = true
raindrop.BrickColor = BrickColor.new("Sand blue")
raindrop.Transparency = 0.5
raindrop.CastShadow = false
raindrop.Material = Enum.Material.SmoothPlastic
raindrop.Position = Vector3.new(cloud.Position.X + math.random(-17.5,17.5),90,cloud.Position.Z + math.random(-27.5,27.5))
raindrop.Size = Vector3.new(0.625,1,0.625)
raindrop.Anchored = false
raindrop.Parent = cloud
mesh.MeshId = "rbxassetid://477374721"
mesh.Parent = raindrop
raindrop.Touched:Connect(function(hit)
raindrop:Destroy()
end)
wait()
end
I would make a conditional to prevent them being deleted by touching other raindrops. You can check their ancestry since the are descendant to the same model/part. It might not be whats causing them to be deleted early but it’s a good starting point.
raindrop.Touched:Connect(function(hit)
if hit ~= cloud and hit.Parent ~= cloud then
raindrop:Destroy()
end
end)
I already set CanTouch to false for the cloud and in my case, there is no way 2 raindrops can touch each other.
Maybe try to make a localscript create rain drops on a cloud. Not only it will fix your problem, but it also reduces server lag.
I don’t know if that’s gonna fix your issue. Please let me know if it worked or the problem persists.
Could you tell me what to really do? I copied and pasted the code from the script into a localscript. It’s not making rain at all.
Did you changed from local cloud = script.Parent
to local cloud = workspace.Cloud
?
If you didn’t, change it to a specified cloud in workspace. And make sure that the localscript is in StarterPlayerScripts
.
Thanks! It actually works man! One question: why does it?
Put a print in the original server script to find out.
raindrop.Touched:Connect(function(hit)
print(hit)
raindrop:Destroy()
end)
You mean why the rain drops disappear in mid air on server script but not on client script?
That’s because on server, things can get delayed. While on client, it perfectly times.
Alright, I get it. So would you personally use localscripts whenever possible in your game?
It depends on if I want to prevent server lag from repeatly creating parts and/or I want to perfectly time on something. If you have more question, you can message me instead.
1 Like