Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to prevent my "pet" from falling out of the world with this script?

So I have a pretty basic script here.

local NewPet = script.Parent
NewPet.CanCollide = false
local PetPos = Instance.new("BodyPosition", NewPet)
local PetGyro = Instance.new("BodyGyro", NewPet)
PetGyro.MaxTorque = Vector3.new(400000,400000,400000)
local Owner = '14zanderbilt'
while wait(0.01) do
	wait()
	local OwnerObj = workspace:WaitForChild(Owner)
	local OwnerPos = OwnerObj.HumanoidRootPart.Position
	local StopAt = ((OwnerPos - NewPet.Position).magnitude - 5) * 100000
	PetPos.P = StopAt
	PetPos.Position = OwnerPos + Vector3.new(-3,5,3)
	PetGyro.CFrame = OwnerObj.HumanoidRootPart.CFrame
end

Tho only problem is, that when I have a too big of a "pet", it falls out of the world. Any ideas? Please note that the script is a server script, and that it works with a "light"/small "pet".

12 comments

0

is it serverscript?

0

Yes.

0

Well what I was thinking is that you could use localscript and then use game:GetService("RunService").RenderStepped:Connect() but it may not work in server

0

I would prefer it to be a server script.

0

Plus, my "pet" is falling out the world. How would a turning it into a local script stop that?

0

I don't know because I don't think it will work on Server. But I think you can make CanCollide true.

0

It still falls. Not through the baseplate, but it just falls.

0

But where is the pet located? On the baseplate? If it is, try the run function so that you can see exactly what is going on.

0

Why does it matter where the pet is located!?!? It just falls through the stupid floor.

0

Is the baseplate's CanCollide property false?

0

No lol.

0

And if it was, I would would fall through the floor.

3 answers

It's falling out of the world because its CanCollide property is false. This means that wherever the pet is, it will fall right through the world and after a while, it will despawn. Meaning it can't follow you.

local NewPet = script.Parent
	NewPet.CanCollide = true
	local PetPos = Instance.new("BodyPosition", NewPet)
	local PetGyro = Instance.new("BodyGyro", NewPet)
	PetGyro.MaxTorque = Vector3.new(400000,400000,400000)
	local Owner = '14zanderbilt'
	while wait(0.01) do
	    wait()
	    local OwnerObj = workspace:WaitForChild(Owner)
	    local OwnerPos = OwnerObj.HumanoidRootPart.Position
	    local StopAt = ((OwnerPos - NewPet.Position).magnitude - 5) * 100000
	    PetPos.P = StopAt
	    PetPos.Position = OwnerPos + Vector3.new(-3,5,3)
	    PetGyro.CFrame = OwnerObj.HumanoidRootPart.CFrame
	end

1 comment

0

Read the comments please. It would just fall without going through the baseplate. It doesn't do that with a smaller "pet", but it does when I make the "pet" larger.

I think you can use WeldConstraint. This will keep it attached.

local NewPet = script.Parent
NewPet.CanCollide = false
local PetPos = Instance.new("BodyPosition", NewPet)
local PetGyro = Instance.new("BodyGyro", NewPet)
PetGyro.MaxTorque = Vector3.new(400000,400000,400000)
local Owner = '14zanderbilt'
while wait(0.01) do
    wait()
    local OwnerObj = workspace:WaitForChild(Owner)
    local OwnerPos = OwnerObj.HumanoidRootPart.Position
    local StopAt = ((OwnerPos - NewPet.Position).magnitude - 5) * 100000
    local Weld = Instance.new("WeldConstraint")
    Weld.Parent = NewPet
    Weld.Part0 = NewPet
    Weld.Part1 = OwnerObj.HumanoidRootPart
    PetPos.P = StopAt
    PetPos.Position = OwnerPos + Vector3.new(-3,5,3)
    PetGyro.CFrame = OwnerObj.HumanoidRootPart.CFrame
end

If this doesn't work, leave your problems in the comments and I will be happy to help you (as said below).

Happy to help, b_mni.

3 comments

0

I do NOT want it welded. I have other scripts that will break if I do that.

0

ok :(

0

Thanks for trying tho lol

Try creating a remote event to transport server to local and local to server. It might work because only one side of the game can see it.

1 comment

0

Read the stupid description. IT'S A STUPID server script lolololol. But seriously please read the description. Also, even if I could only see it, it would still fall through the ding dong floor.

This discussion is preserved as it was. New answers, comments, and votes are closed.