Tweening Part Script Not Working

Hello!

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.


image
(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)

All help is appreciated!

1 Like

Use Vector3.new for Parts
UDim2.new is for GUIs

1 Like

I changed it however it still doesn’t work : /

Did you make sure both Touched and TouchEnded works with a print statement?

local tweenservice= game:GetService("TweenService")
local Part = script.Parent

local goal = {}
goal.Size = Vector3.new(0.047, 0.002, 0.001)

local goal2 = {}
goal2.Size = Vector3.new(15.352, 0.712, 0.326)


game.Workspace:WaitForChild("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)

game.Workspace:WaitForChild("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)

Give this a try.

I just tried it and It’s not printing anything…

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)
1 Like

LocalScript doesn’t work when it’s child of a part in workspace.
Use a script

2 Likes

Yeah, why is he using a local script lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.