Making a pet bound to a part with Cframe

I’ve been trying to make a cloud that follows my gun tool like a pet.
When I run the game, the cloud drops to the floor instead of being joined to the part in any way.
I’ve been looking for solutions on the DevHub but none of them have worked for me.

while true do
local clou = script.Parent
local cf = script.Parent.CFrame

	cf = clou.Parent.CFrame * (2,2,-3)
1 Like

If you want to simply attach the pet to the gun, offset by a certain amount, you can use a weld. Otherwise, if you want the pet to look more like a pet you can look into using BodyMovers.

I’m trying not to use welds because I want it to stay above the gun on a certain axis (following the tool but staying a couple blocks away on one axis) and I’m not sure what BodyMovers are but I will look into it.

When you do

local cf = script.Parent.CFrame

You are just reading the value of the CFrame at that point in time; if you change the value of cf, this won’t change the value of script.Parent.CFrame.

So how would I fix this? I thought what it did was find the CFrame at every repeat and change Script.Parent’s Cframe to that.

You can still use welds if there is a space between the objects.

I’d reccomend using BodyMovers to position the cloud, as it can look more natural (i.e. it doesn’t immediately snap to the new position).

Could we have a look at the heirachy of the parts? In the code you gave, there is only reference to the cloud part.

I may have gotten my point across wrong, I’m looking to find a less stiff way to keep it attached above the gun. I’m currently experimenting with BodyPositions instead of welds to see if it would work.


Using AlignPosition and AlignOrientation objects might be easier.

This is working on a bigger level but I’m wondering if there’s a way for the cloud not to close the distance between it and the gun because I didn’t find anything on the wiki page about that kind of function.

Sure, for the AlignPosition, I would parent the second attachment (Attachment1) to terrain. Then, I would use RunService.Heartbeat to update the attachment’s CFrame to the gun’s CFrame + the desired offset every frame. Just remember to disconnect the function when the part is destroyed.

If you didn’t want to parent the second attachment to terrain, you could also possibly use the new OneAttachment mode property. However, I have not messed around much with it myself.

This could work for me but I’m not sure if this would work in the way I plan on using the gun, I’m thinking just moving the attachment on the gun’s side up and off the gun.

That’d work too probably be easier and then you don’t have to mess around with RunService.

Right, I tried out moving the attachment and it is sufficient for now. Thanks for helping me figure it out :slight_smile: