So I recently made a script where it emits a raycast from the humanoidrootpart and detect if there’s something above and then make snow particles invisible. It’s a script for realism and also because it’s annoying where there’s snow inside. But that’s not the issue, I’m getting this error because I made 2 collisiongroups, one for trees in the outside area of the map and the default one. I then set the raycast collision group to the default one and not the trees one but it gave me an error. Now, the snow particles are off at all times as if something is above me but there isn’t.
Here’s the script:
-- Get the particle system from the workspace
local particle1 = game.Workspace.CameraPart.ParticleEmitter
local particle2 = game.Workspace.CameraPart.ParticleEmitter2
local particle3 = game.Workspace.CameraPart.Particles
local particle4 = game.Workspace.CameraPart2.ParticleEmitter
local particle5 = game.Workspace.CameraPart2.SnowFlake
local replicatedEvent = game.ReplicatedStorage:FindFirstChild("MyCustomEvent")
OldP1Value = particle1.Transparency
OldP2Value = particle2.Transparency
OldP3Value = particle3.Transparency
OldP4Value = particle4.Transparency
OldP5Value = particle5.Transparency
-- Define a function to check if a player is under any part using raycasting
local function checkPlayerUnderPart(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character and character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
local raycastResult = workspace:Raycast(humanoidRootPart.Position, Vector3.new(0,-1,0)*100)
local RaycastParameters = RaycastParams.new()
RaycastParameters.CollisionGroup = "Default"
if raycastResult and raycastResult.Instance:IsA("BasePart") then
-- Disable the particle system if the player is under a part
replicatedEvent:FireClient(player, "disableParticle")
else
-- Enable the particle system if the player is not under any part
replicatedEvent:FireClient(player, "enableParticle")
end
end
end
-- Connect the function to the player's character
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(char)
coroutine.wrap(function()
while wait(0.1) do
if player.Character ~= nil then
local character = player.Character
local raycastParams = RaycastParams.new();
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist;
raycastParams.FilterDescendantsInstances = {player.Character};
raycastParams.CollisionGroup = "Default"
local ray = workspace:Raycast(character:WaitForChild("HumanoidRootPart").Position, Vector3.new(0, 15, 0) * 100, raycastParams);
if ray and ray.Instance:IsA("BasePart") then
-- If the player is under any part, call the function to disable the particle system
checkPlayerUnderPart(player)
else
-- If the player is not under any part, enable the particle system
replicatedEvent:FireClient(player, "enableParticle")
end
end
end
end)();
end)
end)
And here’s the local script it runs:
local replicatedEvent = game.ReplicatedStorage:FindFirstChild("MyCustomEvent")
local particle1 = game.Workspace:WaitForChild("CameraPart").ParticleEmitter
local particle2 = game.Workspace:WaitForChild("CameraPart").ParticleEmitter2
local particle3 = game.Workspace:WaitForChild("CameraPart").Particles
local particle4 = game.Workspace:WaitForChild("CameraPart2").ParticleEmitter
local particle5 = game.Workspace:WaitForChild("CameraPart2").SnowFlake
local replicatedEvent = game.ReplicatedStorage.MyCustomEvent
local tweenService = game:GetService("TweenService")
replicatedEvent.OnClientEvent:Connect(function(eventName)
if eventName == "disableParticle" then
particle1.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0,1), NumberSequenceKeypoint.new(1,1)}
particle2.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0,1), NumberSequenceKeypoint.new(1,1)}
particle3.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0,1), NumberSequenceKeypoint.new(1,1)}
particle4.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0,1), NumberSequenceKeypoint.new(1,1)}
particle5.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0,1), NumberSequenceKeypoint.new(1,1)}
elseif eventName == "enableParticle" then
particle1.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0,0.9), NumberSequenceKeypoint.new(1,0.9)}
particle2.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0,0.9), NumberSequenceKeypoint.new(1,0.9)}
particle3.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0,0.4), NumberSequenceKeypoint.new(1,0.4)}
particle4.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0,0), NumberSequenceKeypoint.new(1,0)}
particle5.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0,0), NumberSequenceKeypoint.new(1,0)}
end
end)