I am making a game where you have anxiety 0.5/s but when you go into the light (a hitbox) that is anchored and uncollidable it decreases 0.25/s. But the event just refuses to work with no errors
-- AnxietyTrigger.lua (LocalScript or Script depending on design)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AnxietyManager = require(ReplicatedStorage:WaitForChild("AnxietyManager"))
local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local Part = script.Parent
Part.CanCollide = false
Part.CanTouch = true
-- Optional visual/audio feedback
-- Part.Transparency = 1 -- Uncomment to make invisible
-- Part.CanQuery = false -- Optional: exclude from raycasts
local debounce = false
local cooldown = 1 -- seconds between triggers
RunService.Heartbeat:Connect(function()
if debounce then return end
local touchingParts = Workspace:GetPartsInPart(Part)
for _, hit in ipairs(touchingParts) do
local character = hit:FindFirstAncestorOfClass("Model")
if character and character:FindFirstChild("Humanoid") then
debounce = true
print("Anxiety triggered by:", character.Name)
AnxietyManager.RemovePercentage(0.25)
-- Optional: Sound/particle effect
-- ReplicatedStorage.TriggerAnxietyFX:FireClient(game.Players:GetPlayerFromCharacter(character))
task.wait(cooldown)
debounce = false
break
end
end
end)