Pets 不是 Player 的有效成员

我遇到了这个错误:

Pets 不是 Player "Players.levstar86" 的有效成员

非常感谢你的帮助

    game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new('Folder', player)
    leaderstats.Name = 'leaderstats'

    local pets = Instance.new('Folder', player)
    pets.Name = 'Pet'

    local coins = Instance.new('IntValue', leaderstats)
    coins.Name = 'Coins'
    coins.Value = 5000

    player.CharacterAdded:Connect(function(char)
        local attachment = Instance.new('Attachment', char.HumanoidRootPart)
        attachment.Name = 'CharacterAt'
    end)
end)

game.ReplicatedStorage.Remotes.Add.OnServerEvent:Connect(function(player, amount)
    local currency = 'Coins'
    player.leaderstats[currency].Value = player.leaderstats[currency].Value + amount
end)

game.ReplicatedStorage.RemoteFunctions.EquipPet.OnServerInvoke = function(player, pet)
    local currency = 'Coins'
    local MainPet = game.ServerStorage.Pets:FindFirstChild(pet)

    if not player.Pets:FindFirstChild(MainPet.Name) then
        if player.leaderstats[currency].Value >= MainPet.Price.Value then
            player.leaderstats[currency].Value = player.leaderstats[currency].Value - MainPet.Price.Value
            local clonedPet = MainPet:Clone()
            clonedPet.Parent = player.Character
            clonedPet:SetPrimaryPartCFrame(player.Character.Head.CFrame)

            local atPet = Instance.new('Attachment', clonedPet.PrimaryPart)

            local ap = Instance.new('AlignPosition')
            ap.Parent = clonedPet
            ap.RigidityEnabled = true
            ap.Attachment0 = atPet
            ap.Attachment1 = player.Character.HumanoidRootPart.CharacterAt

            return 'Bought'
        else
            return 'Not enough coins'
        end
    else
        return 'Equip'
    end
end

原文链接 https://stackoverflow.com/questions/70839919

点赞