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
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!
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.