P cannot be assigned to ERROR

As a person who has no knowledge about vectors or cframes, I have no idea what to change. I tried adding a wait after the wing line of code but nothing changed, please help.

local pet = script.Parent

pet.CanCollide = false

local petposition = Instance.new("BodyPosition", pet)
local petgyro = Instance.new("BodyGyro", pet)
petgyro.MaxTorque = Vector3.new(400000, 400000, 400000)
local owner = 'altornativee'



while(1) do
	wait()
	local owner = workspace:WaitForChild(owner)
	local ownerpos = owner.HumanoidRootPart.Position
	local wing = ((ownerpos - pet.Position).Magnitude - 5) * 1000
	petposition.P = wing
	petposition = ownerpos + Vector3.new(0, 10, 0)
	petgyro.CFrame = owner.HumanoidRootPart.CFrame
end

petposition.P = wing

is the line that gives the P cannot be assigned to ERROR

context: I am following a tutorial lua scripting book that was published 2019 by Heath Haskins.

1 Like

Looks like you are overwriting the petposition variable with a Vector3. Change this line to the following:

petposition.Position = ownerpos + Vector3.new(0, 10, 0)
1 Like

Thanks, but I don’t know why we had to add .position when the variable already has position values.

The variable petposition holds a reference to the BodyPosition instance. Position is one of the properties of the BodyPosition instance and therefore you do .Position to access it.

1 Like

Thanks, that makes a lot of sense, I never assigned the position values to “petposition”

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.