Hello, I have been working on a pet but I have some problems with it, I want the pet to always face a certain way with bodygyros and it works but when I tween the pet’s CFrame the bodygyro stops working how can I make it work while the pet is tweening?
Here is my code for tweening:
local TweenService = game:GetService("TweenService")
local partToTween = script.Parent
local clickDetector = partToTween:FindFirstChildWhichIsA("ClickDetector")
local inTween = false
-- Customizable variables
local TWEEN_TIME = 0.25
local TWEEN_ROT_ANGLES = -45
local TWEEN_MOVE_DISTANCE = 3
-- Tween variables
local tweenInfo = TweenInfo.new(
TWEEN_TIME, -- Time
Enum.EasingStyle.Quad, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
true -- Reverses (tween will reverse once reaching its goal)
)
local function activateAction()
-- If the object is tweening, prevent it from being tweened again
if inTween == true then
return
end
-- Calculate new CFrame for object position and rotation
local offsetCFrame = CFrame.new(0, TWEEN_MOVE_DISTANCE, 0)
local rotatedCFrame = CFrame.Angles(math.rad(TWEEN_ROT_ANGLES), 0, 0)
offsetCFrame = offsetCFrame:ToWorldSpace(rotatedCFrame)
local newCFrame = partToTween.CFrame:ToWorldSpace(offsetCFrame)
-- Create a tween and play it
local tweenObject = TweenService:Create(partToTween, tweenInfo, {CFrame = newCFrame})
tweenObject:Play()
inTween = true
tweenObject.Completed:Connect(function()
inTween = false
end)
end
clickDetector.MouseClick:Connect(activateAction)
Here is my other script for rotating:
local part1 = script.Parent-- The part that will turn to face Part2
local part2 = game.Workspace.Part2
while true do
wait()
part1.BodyGyro.cframe = CFrame.new(part1.Position, part2.Position)
end
Both of these scripts are from the developer hub,How do I fix this?
Thank you!