Trying to give the player a gear 3 seconds after a value reaches 0

I’m making a backrooms type game. The player has a sanity meter, and I coded almond water into the game which restores 40/100 sanity. I’m trying to code it so if the sanity value reaches 0, 3 seconds after that (Which is when the player respawns) almond water is added to their inventory/backpack.

This is the current script I’m using. It’s local.

local value = script.Parent
local tool = game.ServerStorage["Almond Water"]
local charName = script.Parent.Parent.Parent.Parent.Parent.Parent.Name
local db = true

while task.wait() do
	if value.Value <= 0 then
		if db == true then
			task.wait(3)
			tool:Clone().Parent = game.Players[charName].Backpack
			db = false
		end
	end
end

Local scripts can’t access ServerStorage.

1 Like

If I change the RunContext to Legacy, it still doesn’t work.