Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

0
is it serverscript? User#29913 36 — 4y
0
Yes. Cynical_Innovation 595 — 4y
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 User#29913 36 — 4y
0
I would prefer it to be a server script. Cynical_Innovation 595 — 4y
View all comments (8 more)
0
Plus, my "pet" is falling out the world. How would a turning it into a local script stop that? Cynical_Innovation 595 — 4y
0
I don't know because I don't think it will work on Server. But I think you can make CanCollide true. User#29913 36 — 4y
0
It still falls. Not through the baseplate, but it just falls. Cynical_Innovation 595 — 4y
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. Lightning_Game27 232 — 4y
0
Why does it matter where the pet is located!?!? It just falls through the stupid floor. Cynical_Innovation 595 — 4y
0
Is the baseplate's CanCollide property false? Lightning_Game27 232 — 4y
0
No lol. Cynical_Innovation 595 — 4y
0
And if it was, I would would fall through the floor. Cynical_Innovation 595 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

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

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. Cynical_Innovation 595 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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.

0
I do NOT want it welded. I have other scripts that will break if I do that. Cynical_Innovation 595 — 4y
0
ok :( User#29913 36 — 4y
0
Thanks for trying tho lol Cynical_Innovation 595 — 4y
Log in to vote
0
Answered by 4 years ago

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.

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. Cynical_Innovation 595 — 4y

Answer this question