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())
COMMUNITY QUESTION
The output is saying attempt to index nil with 'Parent',is it about otherpart.Parent?
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.
