Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

The output is saying attempt to index nil with 'Parent',is it about otherpart.Parent?

local Players = game.Players
local moeda = script.Parent

local function onPartTouched(otherPart)
	
	local parent = otherPart.Parent
	local humanoid = parent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		moeda.Destroy()
		
		local player = Players:GetPlayerFromCharacter(parent)
		local leaderstats = player.leaderstats
		local moneyStat = leaderstats and leaderstats:FindFirstChild("Money")
		if moneyStat then
		moneyStat.Value += 10
		end
	end
end


moeda.Touched:Connect(onPartTouched())

attempt to index nil with 'Parent'

https://prnt.sc/V326_gNGrKqS https://prnt.sc/tUETY7aBKM_P

1 answer

You're trying to connect the Touched event to the result of the onPartTouched function which is nil. Remove the parentheses to pass the function value instead of the result of the function and it should work as expected.

moeda.Touched:Connect(onPartTouched)

This discussion is preserved as it was. New answers, comments, and votes are closed.