Code not running when a union is touched

I’m trying to make it so a leaderstats value is increased when a union is touched but then there is a cool down on touching that union. When the player touches the union nothing happens. There are no errors in the console regarding anything related to this script. I have read the dev hub page on the function Touched to see if I’m doing something wrong but I couldn’t find anything that could help. I have also tried other ways of detecting touches but it still wouldn’t work.

The script is:
local leaf = script.Parent
local canEat = true

local function onPartTouch(otherPart)
	if canEat == true then
		canEat = false
		script.Parent.Transparency = 0.5
		local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
	 	player.leaderstats.GiraffeBux.Value = player.leaderstats.GiraffeBux.Value + 1
		canEat = true
		script.Parent.Transparency = 0


Here is the model for reference. tree.rbxm (6.7 KB) (It’s too tall for a normal character because I have a custom character that is taller than average.)

Quick question, does it print “touched”?

If it doesn’t print touched, it probably has something to do with the function arguments or something.

No, it doesn’t print anything. 30 characters

I tried out your script and it works fine after I made some changes. Try checking if “otherpart”.Parent has a Humanoid to see if it’s actually a character. The union may be touching other objects like “Baseplate” and may cause error in your script. In addition to that, the printing functions may have not fired because that error stopped the whole code.