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

Why I have this error Character is not a valid member of Model,this script supposed to work?

Asked by 4 years ago

Character is not a valid member of Model ^output gives me this error and I don't know what to do

Script

local function equipPet(player,pet)
    local character = player.Character--the problem is here
    if pet ~= nil and character ~= nil then

        if character:FindFirstChild(player.Name.."'s pet") then character[player.Name.."'s pet"]:Destroy() end

        if character.HumanoidRootPart:FindFirstChild("attachmentCharacter")then 
            character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy() 
        end

        pet.Name = player.Name.."'s pet"        

        pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)

        local modelSize = pet.PrimaryPart.CFrame

        local attachmentCharacter = Instance.new("Attachment")
        attachmentCharacter.Visible = false
        attachmentCharacter.Name = "attachmentCharacter"
        attachmentCharacter.Parent = character.HumanoiRootPart
        attachmentCharacter.Position = Vector3.new(1,1,0) + modelSize

        local attachmentPet = Instance.new("Attachment")
        attachmentPet.Visible = false
        attachmentPet.Parent = pet.PrimaryPart

        local alignPosition = Instance.new("AlignPosition")
        alignPosition.MaxForce = 25000
        alignPosition.Attachment0 = attachmentPet
        alignPosition.Attachment1 = attachmentCharacter
        alignPosition.Responsiveness = 25
        alignPosition.Parent = pet.PrimaryPart

        local alignOrientation = Instance.new("AlignOrientation")
        alignOrientation.MaxTorque = 25000
        alignOrientation.Attachment0 = attachmentPet
        alignOrientation.Attachment1 = attachmentCharacter
        alignOrientation.Responsiveness = 25
        alignOrientation.Parent = pet

        pet.Parent = character


    end



end


game.Players.PlayerAdded:Connect(function(player)
---------------Cash system------------------------
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local cash = Instance.new("IntValue")
    cash.Name = "Cash"
    cash.Parent = leaderstats
--------------------------------------------------  

    local inventory = Instance.new("Folder")
    inventory.Name = "PetInventory"
    inventory.Parent = player

    local equippedPet = Instance.new("StringValue")
    equippedPet.Name = "EquippedPet"
    equippedPet.Parent = player 

    player.CharacterAdded:Connect(function(char)
        if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value)then
            equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
        end 
    end)

    equippedPet.Changed:Connect(function()
        if equippedPet.Value ~= nil then
            if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value)then
            equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
            end
        end
    end)
    wait(5)
    equipPet(game.ReplicatedStorage.Pets.Storm)--script that equips a pet called "storm"

end)
0
it happens to me alot lol 3F1VE 257 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

On line 84 you're only assigning one of the 2 parameters, which I'm assuming is the pet. Because you're only assigning one parameter, it's going to be assigning it to the player parameter on your function since you've got that as the first parameter, hence the error, Character is not a valid member of Model, it's because you're trying to get a Character from the pet.

Hope this helps.

0
Thank you I finally found the problem zuperlukas -7 — 4y
Ad

Answer this question