Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

GUI Color tweening with button click?

Asked by 7 years ago

Hello, I was wondering how to make a GUI tween color with a click of a button?

3 answers

Log in to vote
0
Answered by 7 years ago

There is no such thing as "tween color". Guis do not have color objects, only labels, boxes and buttons do. Here is what you would be looking for:

1gui = script.Parent -- TextLabel, not an actual Gui
2function onClick()
3    gui.BackgroundColor3 = Color3.new(43,99,3)
4end
5gui.MouseButton1Down:Connect(onClick)
2
I think he'd like to actually TWEEN something for a beautiful animation, not just instantly change the color :/ Fireorius 51 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

You need to learn how to tween stuff.

I'd learn about it from Eppobot or AlvinBlox.

If you'd like yours truly to teach you how to do the button thing (and possibly about tweening), here you go...

So first, you get the service. You can do:

1local TweenService = game:GetService("TweenService")

Then, you should define the TweenInfo (you can learn about different easing styles here):

1local transitionInfo = TweenInfo.new(0.5, Enum.EasingStyle.Back)

Now, the action. First, call a function for when the button gets clicked:

1script.Parent.MouseButton1Click:Connect(function()
2 
3end)

Then, you can make the tween:

1script.Parent.MouseButton1Click:Connect(function()
2    local tween = TweenService:Create(guiObject, transitionInfo, {BackgroundColor = Color3.fromRGB(255, 128, 0)})
3end)

Now, play the tween:

1script.Parent.MouseButton1Click:Connect(function()
2    local tween = TweenService:Create(guiObject, transitionInfo, {BackgroundColor = Color3.fromRGB(255, 128, 0)})
3    tween:Play()
4end)

Here's the full code (please note that I need you to replace "guiObject" with the GuiObject you'd like to tween):

1local TweenService = game:GetService("TweenService")
2local transitionInfo = TweenInfo.new(0.5, Enum.EasingStyle.Back)
3 
4script.Parent.MouseButton1Click:Connect(function()
5    local tween = TweenService:Create(guiObject, transitionInfo, {BackgroundColor = Color3.fromRGB(255, 128, 0)})
6    tween:Play()
7end)

You have just made a beautiful animation with TweenSerivce. Congrats!

If you encounter a problem or this doesn't work, just let me know. Bye!

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
7 years ago

You can tween a Color3 value using TweenService or Color3:lerp(). I suggest you read up on them. I have provided you with how to use both:

Here's an example on how to do Color3 linear interpolation (lerp):

1local colour = Color3.new(1,1,1) -- This is equivalent to Color3.new(255/255, 255/255, 255/255)
2local gui = script.Parent -- Let's say this is a frame
3wait(2)
4 
5for i = 1, 10 do
6       gui.BackgroundColor3 = gui.BackgroundColor3:lerp(colour, i/10)
7       wait(.1)
8end

Here's how you can use TweenService:

1local gui = script.Parent
2local ts = game:GetService('TweenService')
3local tween = TweenInfo.new(1, 'Linear', 'Out') -- You should read up on TweenInfo.new
4local t = ts:Create(gui, tween, {BackgroundColor3 = Color3.new(1,1,1)})
5 
6t:Play()

Answer this question