it errors and says I’m trying to index nil with leaderstats. How would I go about fixing this?
local p1 = script.Parent.P1
local player = game.Players.LocalPlayer
local function onEat(otherPart)
local hum = otherPart.Parent:FindFirstChild("HumanoidRootPart")
if hum then
script.Parent:ClearAllChildren()
player.leaderstats.Mass.Value = player.leaderstats.Mass.Value + 1
hum.Size = hum.Size + Vector3.new(0.5, 0.5, 0.5)
local Children = otherPart.Parent:GetChildren()
for i, v in pairs(Children) do -- i, v in pairs loop to sort through table of children and find objects named "Part"
if v.Name == "Part" then
v.Size = v.Size + Vector3.new(0.5, 0.5, 0.5)
end
end
end
end
script.Parent.P1.Touched:Connect(onEat)
