Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

TweenPosition Not Working Properly?

I tried to make a button when they purchase it will go down then go up again however it is not going down but the upward part of the script is working please help me

The Head is the button for the tycoon

Don't Mind the functions just the tween

local cost = tbl[1]
		local item = tbl[2]
		local stats = tbl[3]
		stats.Value = stats.Value - cost
		local PurchaseItems = Objects[item.Object.Value]
		local purchasenotification = game.ReplicatedStorage.RemoteEvents.PurchaseNotification
		local ButtonGoalone = {}
		ButtonGoalone.Position = item:FindFirstChild("Head").Position - Vector3.new(0,-0.27,0) -- here
		local ButtonGoaltwo = {}
		ButtonGoalone.Position = item:FindFirstChild("Head").Position + Vector3.new(0,0.27,0)
		local tweeninfo = TweenInfo.new(
		1,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.InOut,
		0,
		false,
		1.5
		)
		local tween1 = tweenservice:Create(item:FindFirstChild("Head"),tweeninfo,ButtonGoalone) -- here
		local tween2 = tweenservice:Create(item:FindFirstChild("Head"),tweeninfo,ButtonGoaltwo)
		tween1:Play()
		wait(1.5)
		item.Head.Color = Color3.fromRGB(43, 168, 51)
		tween2:Play()
		wait(1.5)
		PurchaseItems.Parent = script.Parent.PurchasedObjects
		purchasenotification:FireClient(player,Objects[item.Object.Value].Name)

1 answer

Well, I assume that Head is a part of a Humanoid, and it might be welded to Torso/UpperTorso.

So, what's the fix?

Well, instead of tweening the Head, you can tween the weld instead. Here's a sample script below, and also a little extra information, on saving lines while using tween:

-- Normal script [inside the Humanoid]
local TS = game:GetService('TweenService')

local Head = script.Parent.Head
local Weld = Head:FindFirstChildOfClass('Snap') -- In my case, the humanoid's head contained 'Snap'. You have to check manually which type of Weld was there

local info = TweenInfo.new(
	1, -- The time to complete the Tween
	Enum.EasingStyle.Linear, 
	Enum.EasingDirection.Out,
	0, -- If you don't want to repeat it
	true, -- Set this to 'true', if you want the head to go down, and return back up
	1.5
)

local Goal = {
	C0 = C0 * CFrame.new(0, 0, -0.27) -- C0 is our Part1 offset of the Weld. Make sure to use 'CFrame' as C0 is the CFrame offset. '-0.27' will move the head down. And because of the bool value set to 'true', the head will go back up.
}

local tween = TS:Create(Weld, info, Goal) -- Loading the information

tween:Play()

Lemme know if it helps!

EDIT : You told me that it is a button, I am assuming it is a Part. Then check, whether there is Weld on the Part. If yes, then change the Weld variable in the script from Snap to Weld.

2 comments

0

Oops I didn't specify the head it the button for the tycoon

0

Is your button Welded?

This discussion is preserved as it was. New answers, comments, and votes are closed.