Why is this OnTouch function not detecting a humanoid?

This code was literally working five minutes ago.

Code is supposed to detect a humanoid when the part is touched, and then manipulate that humanoid a bit, however, the script cannot pickup the humanoid’s existence, even though I’m able to do it myself with a print statement.

Can someone help me out?

local r = script.Parent:WaitForChild("return")
local c = script.Parent:WaitForChild("capture")
local r_Show = r:WaitForChild("Showy")
local c_Show = c:WaitForChild("Showy")
local r_Bag = r:WaitForChild("Bag")
local c_Bag = c:WaitForChild("Bag")
local score = workspace:WaitForChild("Score")
local where_cap_drops = workspace --- easy change for maps
local cap = script:WaitForChild("cap")
local holder = script:WaitForChild("holder")
local body_Part = "UpperTorso"
local sign = c_Show:WaitForChild("Img")
local Taken = script:WaitForChild("taken")
local attackers = game.Teams["Bright blue Team"]

c_Bag.Touched:Connect(function(part)
	print(part.Parent.Name)
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	if (humanoid ~= nil) and (Taken.Value == false) then	-- if a humanoid exists, then
		print("ye")
		local user = game.Players:GetPlayerFromCharacter(part.Parent)
		if user.Team == attackers and not part.Parent:FindFirstChild("MoneyBag") then
			holder.Value = humanoid.Parent
			local mb = Instance.new("BoolValue",part.Parent)
			mb.Name = "MoneyBag"
			sign.Parent = game.ServerStorage
			sign:Clone().Parent = humanoid.Parent[body_Part] --- again, change torso to whatever
			Taken.Value = true
			c_Bag.Transparency = 1
		end
	end 
end)

Is the output completely blank as of now?

No. I used this line of code immediately after the OnTouch function: print(part.Parent.Name)

Got this:
Screen Shot 2020-01-22 at 9.27.43 PM

Meaning that it should detect the humanoid and then execute the rest of the code. But it doesn’t.

Could there be something causing the “Taken” value to be checked before the code runs?

1 Like