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)

01local character =  player.Character--problem is here
02 
03if pet ~= nil and character ~= nil then
04 
05    if character:FindFirstChild(player.Name.."'s pet") then character[player.Name.."'s pet"]:Destroy() end
06 
07 
08    pet.Name = player.Name.."'s pet"       
09 
10    pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
11 
12    local modelSize = pet.PrimaryPart.CFrame
13 
14    local attachmentCharacter = Instance.new("Attachment")
15    attachmentCharacter.Visible = false
View all 33 lines...

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

1local 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