Hello fellow developers!
I am making a script where when the player hovers over the part, it will rotate it and lift it up in the air, however, sometimes It will not work or only play the rotate tween.
I have added a task.wait() between the tween, which does fix it somewhat, as it will always play a tween, but now it will sometimes only play the move up tween. (script below)
Also, It will sometimes not play the tween out tween if the player mouse isn’t hovering over it anymore
I have tried to look online, but I cannot find any results similar to my problem
Any help will be appreciated!
local TweenService = game:GetService("TweenService")
local TweenInfoHTL = TweenInfo.new(0.75, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
local TweenInfoHTD = TweenInfo.new(0.35, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
task.wait(1)
for _, Part in workspace:GetDescendants() do
if Part:IsA("Part") then
if Part:FindFirstChild("ClickDetector") then
local TweenInProgress = false
local PreviousPositionY = Part.Position.Y
local PreviousRotation = Part.Rotation
local HoverTweenLevitate = TweenService:Create(Part, TweenInfoHTL, {Position = Vector3.new(Part.Position.X, PreviousPositionY + 1.75, Part.Position.Z)})
local HoverTweenLevitateRotate = TweenService:Create(Part, TweenInfoHTL, {Rotation = Vector3.new(Part.Rotation.X + 34, Part.Rotation.Y + 24, Part.Rotation.Z + 12)})
local HoverTweenDecend = TweenService:Create(Part, TweenInfoHTD, {Position = Vector3.new(Part.Position.X, PreviousPositionY, Part.Position.Z)})
local HoverTweenDecendRotate = TweenService:Create(Part, TweenInfoHTD, {Rotation = PreviousRotation})
local ClickDetector = Part:FindFirstChildWhichIsA("ClickDetector")
ClickDetector.MouseHoverEnter:Connect(function()
print("Entered")
local SelectionBox = Instance.new("SelectionBox")
SelectionBox.Color3 = Color3.fromRGB(255, 255, 255)
SelectionBox.LineThickness = 0.1
SelectionBox.Parent = Part
SelectionBox.Adornee = Part
TweenInProgress = true
print("playing")
task.wait()
HoverTweenLevitateRotate:Play()
task.wait()
HoverTweenLevitate:Play()
HoverTweenLevitate.Completed:Wait()
TweenInProgress = false
print("played")
end)
ClickDetector.MouseHoverLeave:Connect(function()
print("Removing")
if TweenInProgress == true then
HoverTweenLevitate:Cancel()
HoverTweenLevitateRotate:Cancel()
end
if Part:FindFirstChild("SelectionBox") then
Part.SelectionBox:Destroy()
end
TweenInProgress = true
HoverTweenDecendRotate:Play()
task.wait()
HoverTweenDecend:Play()
HoverTweenDecend.Completed:Wait()
TweenInProgress = false
end)
end
end
end