Why is the particle not being destroyed?

its adding the particle but not deleting

local StinkyRemote = game.ReplicatedStorage.Remotes:WaitForChild("Stinky")
local StinkyParticle = game.ReplicatedStorage.Particles:WaitForChild("Stinky")

StinkyRemote.OnServerEvent:Connect(function(plr)
	local character = plr.Character
	if character then
		print("Character found for: "..character.Name)
		local hrp = character:FindFirstChild("HumanoidRootPart")
		if hrp then
			-- Check if the player already has the particle
			local existingStinkyParticle = hrp:FindFirstChild("StinkyParticle")

			if not existingStinkyParticle then
				existingStinkyParticle = StinkyParticle:Clone()
				existingStinkyParticle.Name = "StinkyParticle"
				existingStinkyParticle.Parent = hrp
				existingStinkyParticle.Enabled = true
			end

			if plr:FindFirstChild("MoodsFolder") and plr.MoodsFolder:FindFirstChild("Hygiene") then
				local hygieneValue = plr.MoodsFolder.Hygiene.Value
				if hygieneValue > 35 then
					existingStinkyParticle.Enabled = false
					existingStinkyParticle:Destroy()
				end
			end
		end
	end
end)
1 Like

i do not recommend defining a property in a variable it will most likely not work

local hygieneValue = plr.MoodsFolder.Hygiene
				if hygieneValue.Value > 35 then
					existingStinkyParticle.Enabled = false
					existingStinkyParticle:Destroy()
				end

also please be more specific with your issues

how am i supposed to be more specific its just not deleting the particle if the value is higher than 35

did you already try the script i gave you? the reason for this might be because you are directly defining the object and also the property…

yes i tried still does not work

did you playtest and check the hygiene value from the server and is it above 35, not exactly 35?

yes i did it still doesnt destroy

local existingStinkyParticle = hrp:WaitForChild("StinkyParticle", .1)

i changed this to :WaitForChild instead of :FindForChild, and added a 0.1 wait
now try it

nope its still not deleting the particle if i change it to above 35

somethings wrong with your script, let me observe

local existingStinkyParticle
if not hrp:FindFirstChild("StinkyParticle") then
				existingStinkyParticle = StinkyParticle:Clone()
				existingStinkyParticle.Name = "StinkyParticle"
				existingStinkyParticle.Parent = hrp
				existingStinkyParticle.Enabled = true
			end

You can print your variables to see if they are what you expect:

		if plr:FindFirstChild("MoodsFolder") and plr.MoodsFolder:FindFirstChild("Hygiene") then
                print("MoodsFolder & Hygiene found")  -- if it doesn't print then find out why
                -- maybe you aren't referencing the folders properly
                -- look in the player in the workspace while testing to see if the folders are actually there
				local hygieneValue = plr.MoodsFolder.Hygiene.Value
                print("hygieneValue")  -- if it isn't changing or isn't what you expect then troubleshoot why it isn't
				if hygieneValue > 35 then
					existingStinkyParticle.Enabled = false  -- why do this if you destroy it in the next line anyway?
					existingStinkyParticle:Destroy()
				end
			end

I just realized why are you doing this :sob:

if plr:FindFirstChild("MoodsFolder") and plr.MoodsFolder:FindFirstChild("Hygiene") then

Just do

local MoodsFolder = plr:WaitForChild("MoodsFolder")

if MoodsFolder and MoodsFolder:FindFirstChild("Hygiene") then

WaitForChild() is crucial especially when you are looking for objects inside the player, which doesn’t always load instantly.

what… you need the and it wont work without it

you used plr:FindFirstChild(“MoodsFolder”) to check if it exists which is fine, but in the second statement you didn’t use FindFirstChild to get MoodsFolder which… kinda ruins the whole thing (correct me if i’m wrong)

my edited version was to simplify the whole code, and who knows the moodsfolder could be the reason for this

i cannot understand what you mean could you explain?

(Referring to your if-then statement in the code) You checked if “MoodsFolder” exists using plr:FindFirstChild("MoodsFolder") , which is good. However, after the “and”, you didn’t use FindFirstChild to actually get “MoodsFolder,” and that messes up the whole process. This is just my guess, so don’t believe me instantly (I’m kinda dumb)

I fixed it i needed to check when the value changed

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.