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)
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
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
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
(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)