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

Character is not a valid member of Model what should I do?

Asked by 4 years ago

llocal function equipPet(player,pet)

local character =  player.Character--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


    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.Parent = character.HumanoiRootPart
    attachmentCharacter.Position = Vector3.new(1,1,0) + modelSize

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

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

    pet.Parent = character


end

end

It says that problem is Character is not a valid member of a model

2 answers

Log in to vote
0
Answered by
Grazer022 128
4 years ago

hello there! I’m here to talk about your problem. First of all most of the time the character doesn’t load yet. So i suggest you try this on line 1

local character = player.Character or player.CharacterAdded:Wait()

so if the character hasn’t load yet, it will wait for it to load. Hope this works and helps!

0
Itells me that CharacterAdded is not a valid member of Model zuperlukas -7 — 4y
Ad
Log in to vote
0
Answered by
Sulfone 141
4 years ago

That means that the player you gave is actually model, not a player. Find where a model was accidentally passed, then change it to a player (if the model is related to a player) or prevent equipPet from being used in that case (if the model is not related to a player).

You could quickly check what the model you accidentally passed by printing the passed player. If it's the player's character (this is a guess because not enough of the script was given), you give the result of GetPlayerFromCharacter to equipPet instead of the model directly. You could show the part of the script that uses equipPet if it's not a character and you want to let people find the mistake.

Answer this question