Hey! In the game I’m working on there’s a morphing system. And I made a server script so that when the raycasting detects something above the player it fires an event that disables the snow in the map on the client side. Now, as the title suggests it only works for the player and does not work for the morph.
-- 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)
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)
local character = player.Character or player.CharacterAdded:Wait()
coroutine.wrap(function()
while wait(0.1) do
local raycastParams = RaycastParams.new();
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist;
raycastParams.FilterDescendantsInstances = {player.Character};
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)
local character = player.Character or player.CharacterAdded:Wait()
Why? Your resetting the character when it morphs, and not checking for a new character. Simple fix.
-- 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)
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(character)
coroutine.wrap(function()
while wait(0.1) do
local raycastParams = RaycastParams.new();
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist;
raycastParams.FilterDescendantsInstances = {player.Character};
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)
The problem is not with the morphing script because a lot of other scripts work with the morph it’s just this one. And I’m scared of breaking the morph 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)
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};
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)