Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
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

Log in to vote
0
Answered by
7z99 203 Moderation Voter
2 years ago

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)
Ad

Answer this question