Hello, I have been working on a pet that hops around but I want it to only move in the range I did this:
local tweenService = game:GetService('TweenService')
local firstPart = workspace.Part
function MovePet(pet)
local speed = math.random(.3, 2)
local tweenInfo = TweenInfo.new(
1,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local x = math.random(firstPart.Position.X - firstPart.Size.X/2 , firstPart.Position.X + firstPart.Size.X/2)
local z = math.random(firstPart.Position.Z - firstPart.Size.Z/2 , firstPart.Position.Z + firstPart.Size.Z/2)
local partBPosition = pet.Position + Vector3.new(x,0,z)
local MiddlePosition = (pet.Position + partBPosition) / 2
local mainPosition = MiddlePosition + Vector3.new(0,3,0)
local tween1 = tweenService:Create(pet, tweenInfo, {Position = mainPosition})
local tween2 = tweenService:Create(pet, tweenInfo, {Position = partBPosition})
tween1:Play()
tween1.Completed:Connect(function()
tween2:Play()
end)
wait(3)
end
while true do
wait()
MovePet(workspace.MovingPart)
wait(1)
end
But here is what happens:
How can I fix it?
Thank you!