I am trying to make a simple tween that occurs when a player touches an invisible part. However when the player touches the part the tween doesn’t work and I don’t know what the issue is.
(Neon Part is the part I want to tween and map selection part is the part that triggers the function when touched)
The Script:
local tweenservice= game:GetService("TweenService")
local Part = script.Parent
local goal = {}
goal.Size = UDim2.new(0.047, 0.002, 0.001)
local goal2 = {}
goal2.Size = UDim2.new(15.352, 0.712, 0.326)
game.Workspace.MapSelectionPart.Touched:Connect(function()
local tweeninfo = TweenInfo.new(
1,
Enum.EasingStyle.Quint,
Enum.EasingDirection.In,
0,
false,
0
)
tweenservice:Create(Part, tweeninfo, goal2):Play()
print("Animation Complete")
end)
workspace.MapSelectionPart.TouchEnded:Connect(function()
local tweeninfo = TweenInfo.new(
1,
Enum.EasingStyle.Exponential,
Enum.EasingDirection.Out,
0,
false,
0
)
tweenservice:Create(Part, tweeninfo, goal):Play()
end)
In this case, it’s not because your tweens are not working, but your touch events are not activated. Try these events on another part other than the ones you have and implement the tween afterward.
You access game.Workspace.MapSelectionPart on Touched but are accessing workspace.MapSelectionPart on TouchEnded. It’s either that or you may need a debounce, Touched may continuously fire while the part is being touched. Which means that all the Tweens are being cancelled by the next one and actually none of them are given time to finish or even start.
local debounce = false;
game.Workspace.MapSelectionPart.Touched:Connect(function()
if not deboune then
debounce = true;
-- ... rest of code
end
end)
workspace.MapSelectionPart.TouchEnded:Connect(function()
-- ... rest of code
local tween = tweenservice:Create(Part, tweeninfo, goal2); -- allocate tween so you can wait for the Completed event to fire
tween:Play();
-- wait for it to complete before resetting debounce
tween.Completed:connect(function()
debounce = false;
end)
end)