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

Attempt to index nil with 'Parent' - How to fix this?

Asked by 3 years ago

I'm trying to make a trail shop and I'm currently stuck on the phase where my Module Script returns this error:

ReplicatedStorage.ModuleScripts.Insert - attempt to index nil with 'Parent'

I've searched around both scriptinghelpers and the Roblox Devforum but I couldn't find the answer to my problem. Here's the code:

module.InsertTrail = function(plrname, trail)
    local plr = game.Players:FindFirstChild(plrname)
    plr.CharacterAdded:Connect(function(char)
        local at0 = char.Head:WaitForChild('Attachment0')
        local at1 = char.HumanoidRootPart:WaitForChild('Attachment1')


        local tr = trail:Clone() 
        tr.Parent = char -- Error Line
        tr.Attachment = at0
        tr.Attachment1 = at1
    end)

    game.ReplicatedStorage.Trail.OnServerEvent:Connect(function()
        plr.Character:FindFirstChildWhichIsA('Trail'):Destroy()
    end)
end

Any help will be appreciated! :)

Answer this question