How to find objects in character with FindFirstChild?

Well. I need help with this and it is that the script detects when a specific object touches a part, it detects it and it does its function and it works. But in the ProximityPrompt part, it should also detect the tool but it doesn’t.

local OpenPos = script.Parent.Parent.Parent.Parent:WaitForChild("Ventanilla"):WaitForChild("OpenPos")
local ClosePos = script.Parent.Parent.Parent.Parent:WaitForChild("Ventanilla"):WaitForChild("ClosePos")
local Ventanilla = script.Parent.Parent.Parent.Parent:WaitForChild("Ventanilla"):WaitForChild("Ventanilla")
local Herramienta = script.Parent.Parent.Parent.Parent:WaitForChild("Ventanilla"):WaitForChild("Herramienta")
local openSound = script.Parent.Parent.Parent.Parent:WaitForChild("Base"):WaitForChild("Base"):WaitForChild("AbirPuerta")
local closeSound = script.Parent.Parent.Parent.Parent:WaitForChild("Base"):WaitForChild("Base"):WaitForChild("CerrarPuerta")
local Touch = script.Parent.Parent.Parent.Parent.Touch
local tweenService = game:GetService("TweenService")
Herramienta.Value = true
local ButtonPress = false
local ButtonPress2 = false
local IdComida = script.Parent.Parent.Parent.Parent:WaitForChild("TipoDeComida")
local PosicionComida = script.Parent.Parent.Parent.Parent:WaitForChild("PlatoyPos")
local FoodInicioPos = PosicionComida.FoodEndPos
local FoodEndPos = PosicionComida.FoodEndPos
local Proximity = script.Parent


Touch.Touched:Connect(function(player)
	ButtonPress = false
	ButtonPress2 = true
	if player.Parent:FindFirstChild("Card") ~= nil then
		Proximity.Enabled = true
		IdComida.Value = "Card"
		Proximity.ActionText = "Calentar Card"
	end
	if player.Parent:FindFirstChild("Esposas") ~= nil then
		Proximity.Enabled = true
		IdComida.Value = "Esposas"
		Proximity.ActionText = "Calentar Esposas"
	end
end)

Touch.TouchEnded:connect(function(player)
	ButtonPress = false
	ButtonPress2 = true
	Proximity.Enabled = false
end)

local debounce = true
Proximity.Triggered:Connect(function(player)
	if debounce == true then
		debounce = false
		if Herramienta.Value == true then
			Herramienta.Value = false
			closeSound:Play()
			tweenService:Create(Ventanilla,TweenInfo.new(.35),{CFrame = OpenPos.CFrame}):Play()
			wait(0.3)
			print("god")
			if player.Parent:FindFirstChild("Card")  ~= nil then
				local comida = player.Parent:FindFirstChild("Card")
				if comida then
				comida.Parent = PosicionComida
				tweenService:Create(comida,TweenInfo.new(.35),{CFrame = FoodInicioPos.CFrame}):Play()
				wait(0.4)
					tweenService:Create(comida,TweenInfo.new(.35),{CFrame = FoodEndPos.CFrame}):Play()
				end
			end
			--tweenService:Create(Ventanilla,TweenInfo.new(.35),{CFrame = ClosePos.CFrame}):Play()
			Herramienta.Value = true
			wait(0.4)
			debounce = true
		end
	end
end)

okay so ima 1st point out that using Touch and TouchEnded at the same time would be very buggy since TouchEnded functions may fire constantly. i would reccomand you using another method like Region3, RayCast or even Magnitude since Touch and TouchEnded may be unreliable as mentioned here

also before you check if “card” exist in the Part (or limb) that touched the part you should probably check if Touched.Parent even is the player’s character. you can use :GetPlayerFromCharacter() to check if it’s the player’s character it will return nil if its not.
im yet confused why you put player as arguement as the 1st parameter of the .TouchedEvent since its not the actual player. its the instance object that has touched the part with the .Touched

this was in the Triggered event. the 1st paramater of Triggered event is the player’s instance that triggered the proximity prompt. this is mentioned here DevHubLink

just to make sure “Card” is the tool correct? well if a tool is selected it would be paranted inside the player’s Character. not the PlayerService? since what ur doing here is looking for something named “Card” in the PlayerSerivce since that is where the player is parenated.

1 Like

Encontré una solución alterna.

En vez de usar eso, usé:
Local Player = Workspace:FindFirstChild(Player.Name)