-
What do you want to achieve?
A simple rain system that first, checks for an obstruction above the player (like a roof). If an obstruction is found, rain particles around the player are disabled. If no obstruction is found, then the particles are enabled. Here is my code.
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local RootPart = Character:WaitForChild("HumanoidRootPart")
local Emitter = game:GetService("ReplicatedStorage").Emitter:Clone()
local RainParticle = Emitter.Rain.ParticleEmitter
local SplashParticle = Emitter.Splash.ParticleEmitter
local RainPart = RainParticle.Parent
local SplashPart = SplashParticle.Parent
local RainSound = game:GetService("SoundService").Rain
local IndoorSound = game:GetService("SoundService")["Indoor Rain"]
local RunService = game:GetService("RunService")
Emitter.Parent = game:GetService("Workspace") --Setting Default Values
RainParticle.Enabled = false
SplashParticle.Enabled = false
local Active = true
while wait(.25) do
Humanoid.Died:Connect(function()
Active = false
Emitter:Destroy()
end)
if Active then
local Position = RootPart.Position - Vector3.new(0,2.75,0)
Emitter:MoveTo(Position)
if not RootPart then return end
local Origin = RootPart.Position
local Direction = Origin + Vector3.new(0,100,0)
local RayParameters = RaycastParams.new()
RayParameters.FilterDescendantsInstances = {RainPart, SplashPart, Character:GetChildren()}
RayParameters.FilterType = Enum.RaycastFilterType.Blacklist
local RayResult = workspace:Raycast(Origin, Direction, RayParameters)
if RayResult then --Obstruction
if RayResult.Instance.ClassName == "MeshPart" then --MeshParts dont count as obstructions
print("No Obstruction Located")
RainParticle.Enabled = true
SplashParticle.Enabled = true
IndoorSound.Volume = 0
IndoorSound.TimePosition = 0
RainSound.Volume = 1
else
print("Obstruction Located")
print(RayResult)
RainParticle.Enabled = false
SplashParticle.Enabled = false
RainSound.Volume = .5
--RainSound.TimePosition = 0
IndoorSound.Volume = 1
end
elseif RayResult == nil then --No Obstruction
print("No Obstruction Located")
RainParticle.Enabled = true
SplashParticle.Enabled = true
IndoorSound.Volume = 0
IndoorSound.TimePosition = 0
RainSound.Volume = 1
end
end
end
-
What is the issue?
This system uses a simple raycast that fires straight up, but for some reason the raycast is being really buggy (detecting objects that arent above the player??? It fires straight up! I blacklisted the rain particle base and the character from being detected so it cant be that.)
-
What solutions have you tried so far?
I have no idea where to start on the problem but I thought it might have something to do with studio settings, so I tried it out but with no luck. Maybe there’s a problem with my code but I can’t figure it out. Everything seems to run fine in a separate studio tab. Any Ideas?
Heres a studio file to mess around with:
Dynamic Rain Testing.rbxl (40.3 KB)