Problem with :IsDescendantOf!

hello everyone, the :IsDescendantOf statement is returning false what is the fix of this?
yeah so i am trying to make the button get 1$ countinously but i am getting false statement

local playerService = game:GetService("Players")
local button = script.Parent.redbutton

local function onHumanoidTouched(humanoid)
	
	local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
	
	if player then
		
		local leaderstats = player:FindFirstChild("leaderstats")
		
		if leaderstats then
			local cash = leaderstats:FindFirstChild("Cash")
			
			if cash then
				local pass2x = player.ButtonsFolder.Cash2x.Value
				local pass3x = player.ButtonsFolder.Cash3x.Value
				local pass5x = player.ButtonsFolder.Cash5x.Value
				if humanoid:IsDescendantOf(button) then 
					print("true")
				else
					print("false")
				end
				while humanoid:IsDescendantOf(button) do
					print("done5")
					cash.Value = cash.Value + 1 -- add $1 continuously
					wait(1)
				end
			end
		end
	end
end

button.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
	
	if humanoid then
		onHumanoidTouched(humanoid)
	end
end)
1 Like

IsDescendantOf returns true if the instance is a child or ancestor of the instance in the argument, i would recommend using .Touched and .TouchEnded combined to do what you want

1 Like

IsDescendantOf isn’t activated. It hasn’t been activated for a while now. Therefore, it’s useless. To find the descendant of an object, you can use the second parameter of FindFirstChild.

myPart = workspace:FindFirstChild("Part", true)
1 Like

hey, can you tell how would it worked out because I don’t think it would work because I want to find the player not the part?

1 Like