Trying to rotate a text in TextButton

Hello. I am currently trying to make a script that when a player clicks a TextButton, the Text of this button will rotate 5 degrees then rotate -5 to come back at his original position. Here’s the script that I got:

local TweenService = game:GetService("TweenService")
local label = script.Parent.Parent.Shop
local shopframe = script.Parent.Parent.Parent.Frames.ShopFrame

local function rotateText()
	local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, true, 2)
	local goal = {Rotation = math.abs(script.Parent.Parent.Shop.Rotation) * -1}
	local tween = TweenService:Create(label, tweenInfo, goal)
	tween:Play()
	tween.Completed:Connect(rotateText)
end

label.MouseButton1Click:Connect(function()
	if shopframe.Visible == true then
		rotateText()
		shopframe.Visible = false
	else
		rotateText()
		shopframe.Visible = true
	end
end)

It also makes another frame visible when the player clicks it. The problem is that whenever I click the button, nothing happens: it doesn’t rotate but the ShopFrame appears. Can somebody help?

Thanks

The shop button should not disapear? well test this code:

local TweenService = game:GetService("TweenService")
local label = script.Parent.Parent.Shop
local shopframe = script.Parent.Parent.Parent.Frames.ShopFrame

local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, true, 0)

local function rotateText()
	local goal = {Rotation = 30} -- changed to 30 degrees to make it noticeable
	local tween = TweenService:Create(label, tweenInfo, goal)
	tween:Play()
end

label.Activated:Connect(function()
	warn("clicked")
	rotateText()
	shopframe.Visible = not shopframe.Visible
end)

This still not works… The text does not rotate I don’t know why

I tested that code and works, but its not rotating the text, its rotating the button, cause you stated that in your code, I supposed you wanted to rotate the entire button not only the text.

When testing that code, nothing rotates at all? then its an issue with your references, or something else. Could you show how your GUI hierarchy looks like?

Nevermind, I just created a textlabel in the button and rotated it instead and it works…

yeah, if you want to only rotate the text, you should do that…

1 Like