BodyPosition not working properly

How it should look:
RobloxScreenShot20181219_105219422
How it actually looks:


As you can see, there is no model following the player. Now when I check the BodyPosition.Position as you can see it’s like -499, etc. Now the players HumanoidRootPart is also around there (the BodyPosition is suppose to be slightly behind and above the HumanoidRootPart) and when I move, the BodyPosition.Position moves as well. But I can’t see the actual model. The models are the exact same thing. No difference at all.

The model isn’t transparent either.

local pets = workspace.PetStorage
local player = game.Players.LocalPlayer

function renderPet(target, pet)
	pet.CanCollide = false
	local targetPlr = game.Players:GetPlayerFromCharacter(target)
	
	local bp = Instance.new("BodyPosition")
	local bg = Instance.new("BodyGyro")
	
	bg.D = 750
	bg.MaxTorque = Vector3.new(25000,25000,25000)
	bg.P = 5000
	
	bp.D = 400
	bp.MaxForce = Vector3.new(1250,10000,1250)
	bp.P = 2000
				
	bg.Parent = pet
	bp.Parent = pet
	
	pet.CFrame = target.HumanoidRootPart.CFrame + Vector3.new(0, 10, 0)

	spawn(function()
		local backUpTarg = target
		
		while target do
			if target == player.Character then
				wait()
			else
				wait(.25)
				if player.Character then
					local dist = (player.Character.HumanoidRootPart.Position-target.HumanoidRootPart.Position).magnitude
					if dist > 35 then
						wait(1.5)
					end
				end
			end
			
			bg.CFrame = target.HumanoidRootPart.CFrame
			bp.Position = CFrame.new(target.HumanoidRootPart.CFrame * Vector3.new(0, 2, 4)).p			
		end
	end)
end

pets.ChildAdded:connect(function(pet)
repeat wait() until pet:FindFirstChild("Target")
local owner = pet.Target.Value
if owner then
    renderPet(owner, pet.Torso)    
end
end)

Could there be something in a game that could be ruining this from happening??

2 Likes

BodyPosition.Position

HumanoidRootPart.Position

Nothing can be seen around the player:


Also put prints on every line of the script, the script does not stop, it’s constantly running. When the player walks around the BodyPosition does change to match that of the player. It’s just the model is no where to be seen.

The pet might be getting stuck on a wall or something. What’s the position of the pet when you can’t see it? Is the pet set to CanCollide = false? Are you CFraming the pet to the player at spawn, or is the pet always created at 0,0,0 (and then moves to the player)?

Well in the script it sets the cancollide to false. Even if theres only the part (the torso to the pet) and its cancollide os false it still doesn’t show up.

The position of the part is like miles away, but I didn’t think position of the pet mattered, only the BodyPosition.

Is ‘Target’ getting set properly? It doesn’t look like the owner is ever being assigned. It also looks like the if statement in the while loop is unnecessary. And it ALSO seems like your setting the CFrame of a body gyro, which won’t do anything. And it ALSO ALSO looks like ‘targetPlr’ is an unnecessary variable.

I set owner value inside a seperate script.

Setting th CFrame of the Gyro sets the models orientation, so it actually faces the player.

As for the other stuff, this was someone elses sceipt that I’ve made small edits to. I guess looking back over it, I can just remove both the if statement and targetplr.

It looks like you are trying to do physics manipulation of the pet on the client. For this to work, the client that you want to control the pet must have network ownership of it. Call pet.Torso:SetNetworkOwner(player) on the server to set network ownership.

2 Likes

But it works perfectly in an empty place??

Network ownership is automatically assigned by default, so it’s possible that this happens in an empty baseplate but not your full game. You need to explicitly assign it for consistent results. I’m fairly sure this is your issue, but post if not.


Moved them so they were stored in the repstorage close to where the player would receive them, so no getting stuck in walls. As you can see, they spawn in, but that’s it. I can hit them and they do nothing, they just sit there. The BodyPosition is still moving tho. Just not the model. The model is also unanchored and cancollide is set to false

Where would I put this line?
pet.Torso:SetNetworkOwner(player)

I editted the code a bit more, to remove useless stuff

local pets = workspace.PetStorage
local player = game.Players.LocalPlayer

function renderPet(target, pet)
	pet.CanCollide = false	
	local bp = Instance.new("BodyPosition")
	local bg = Instance.new("BodyGyro")
	
	bg.D = 750
	bg.MaxTorque = Vector3.new(25000,25000,25000)
	bg.P = 5000
	
	bp.D = 400
	bp.MaxForce = Vector3.new(1250,10000,1250)
	bp.P = 2000
				
	bg.Parent = pet
	bp.Parent = pet
	
	pet.CFrame = target.HumanoidRootPart.CFrame + Vector3.new(0, 10, 0)

	spawn(function()
		while target do
			bg.CFrame = target.HumanoidRootPart.CFrame
			bp.Position = CFrame.new(target.HumanoidRootPart.CFrame * Vector3.new(0, 2, 4)).p			
			wait()
		end
	end)
end

pets.ChildAdded:connect(function(pet)
repeat wait() until pet:FindFirstChild("Target")
	if pet.Name == player.Name then
	    pet.Target.Value = player.Character
	    local owner = pet.Target.Value
	    if owner then
	        renderPet(owner, pet.Torso)    
	    end
	end
end)

I was thinking Network ownership is probably the issue also. The pet being “miles away” suggests that when you run the full game, it’s probably not within your character’s simulation radius, so the pet is server-owned and “sleeping” (not physically simulated). Definitely try assigning ownership, but also try initially positioning it just a few studs away from your character; where it is in the world relative to the character of the player who has ownership of it does matter.

That’s what this line is for in the code. It does not seem to wanna work properly. Even when stored right next to where theyd spawn however, they dont move. They just sit there, even while Bodyposition numbers are changing, it just remains on the floor, I can hit it etc and it just does nothing.

Do you have, or can you make, a pared-down example file that reproduces this? I feel like there must be something going on here we can’t see from the screenshots, like some property of the pet that is different on server vs client, for example if it’s spawned with parts collidable or anchored on the server, and these are only changed from a script on the client. I’m not saying this is necessarily the case, but that there may be some non-replicating difference we can see with only client-side screenshots of a few values.

Keep in mind also that properties set locally will not replicate to the server if set when you don’t have ownership. You have ownership of your own character, so you can bodyposition your own avatar all you like and it will always replicate but the rules are very different for things that are not attached to your character. Have you tried doing all control of the pet server-side (no localscripts involved in any way)? Bodyposition changes are interpolated on the client, so everyone should see it move smoothly no matter where you set the BodyPosition.Position from.

Just tried in a place to replicate this but I can’t :confused: in the empty place, it spawns the pet in, but if its far away from the player then it doesnt do anything, not until the player actually goes over and like hits it or something.

I feel like it should have something to do with this line:
pet.CFrame = target.HumanoidRootPart.CFrame + Vector3.new(0, 10, 0)
Idk why, but the pet doesnt get moved over to the player

Here’s an example of it being spawned in away from the player and not doing anything until I actually go over to it. Problem is though this isn’t the case in actual place. It can spawn in, I can see it sitting there, but going over to it does nothing.

Pets.rbxl (342.1 KB)

If anyone wants to have a look. If you click on the Snowman button, you can see the snowman spawn in, but do nothing. You have to physically go over to him to get him to start moving.

I’ll have a look at your system later for you. :slight_smile:

(Since I helped you make it)

Here is the fixed version!

Happy to help. I’ll also DM you a more efficient/easier system to work with and experiment with!


Pets(NinjoFixed).rbxl (885.7 KB)

3 Likes