Hi all! I’m using this code to make a ball follow overhead, but when testing the ball just randomly stops in midair roughly 10-40 seconds after starting. I’m not familiar with scripting, so this might be tripping something up and I’d love if someone could look it over. Thanks!
local pet = script.Parent
function givePet (player)
if player then
local character = player.Character
if character then
local humRootPart = character.HumanoidRootPart
local newPet = pet:Clone ()
newPet.Parent = character
local bodyPos = Instance.new("BodyPosition", newPet)
bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge) -- basically maximum speed and velocity is infinite
local bodyGyro = Instance.new("BodyGyro", newPet)
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
while wait() do
bodyPos.Position = humRootPart.Position + Vector3.new(0, 5, 0)
bodyGyro.CFrame = humRootPart.CFrame
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
givePet(player)
end)
end)
I used the whole script here but the pet didn’t appear at all : ( ty for assistance though
local pet = script.Parent
function givePet (player)
if player then
local character = player.Character
if character then
local humRootPart = character.HumanoidRootPart
local newPet = pet:Clone ()
newPet.Parent = character
local bodyPos = Instance.new("BodyPosition", newPet)
bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge) -- basically maximum speed and velocity is infinite
local bodyGyro = Instance.new("BodyGyro", newPet)
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
task.spawn(function()
while task.wait() do
bodyPos.Position = humRootPart.Position + Vector3.new(0, 5, 0)
bodyGyro.CFrame = humRootPart.CFrame
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
givePet(player)
end)
end)
Hi I used AlignPosition but it seems to just lock the ball in place. I can see it moving and it moves my character when I touch it, but it just seems to lock here.
In the end I’ve scrapped this bit of code and I think it’s malfunction has to do with roblox deprecating BodyPosition. Going to try to figure something else out with AlignPosition.
local RunService = game:GetService("RunService")
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
InitPet(Player)
end)
end)
function InitPet(Player)
local PetReference = script.Parent
if (Player) then
local Character = Player.Character
if (Character) then
local HumanoidRootPart = Character.HumanoidRootPart
local Pet1 = PetReference:Clone()
local Attachment1 = Instance.new("Attachment", Pet1)
local Attachment2 = Instance.new("Attachment", HumanoidRootPart)
local AlignPosition1 = Instance.new("AlignPosition", Pet1)
Attachment2.Position = Vector3.new(0, 5, 0)
AlignPosition1.MaxForce = math.huge
AlignPosition1.MaxVelocity = math.huge
AlignPosition1.Responsiveness = 30
AlignPosition1.Attachment0 = Attachment1
AlignPosition1.Attachment1 = Attachment2
Pet1.Parent = Character
end
end
end
Result:
Extra:
Remember to set the Collision of the “Pet” as false.