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

How do I make this button glow effect?

1 answer

✓ Accepted answer

It's not glowing, it's actually changing its own color to a bright one. You can start with linear interpolation or TweenService.

1.Lerp

Choosing this one results in manufacturing a method called ColorLerp.

local button
local runningId = 0
local speed = 100
local heartbeat = game:GetService("RunService").Heartbeat
local function ColorLerp(c)
	runningId  = (runningId+1)0000
	local now = runningId--Sign up a new ID for this called function
	local start = button.BackgroundColor3
	for alpha=0,1,0.001*math.clamp(speed,1,1000) do
		if runningId ~= now then return nil end--A new function has been fired, interrupt it
		local now = start:lerp(c,alpha)
		button.BackgroundColor3 = now
		heartbeat:Wait()
	end
end

Ohh! There are SO MANY THINGS to explain!

local button--Your button

Let's look at the runningId

local runningId = 0
--...--
runningId  = (runningId+1)0000

Basically, we use running id to register our called function.

if runningId ~= now then return nil end

It means that if there is a newer function being called while the loop is running, stop the function via returning a nil value.

So what is lerp???

Oh! Let's look at a simple example:

local alpha = 0.5
local val = Color3.new(0,0,0):lerp(Color3.new(1,1,1),0.5)
print(tostring(val))
--Results: 0.5,0.5,0.5

The alpha is actually the percentage of the start(0,0,0) to the end(1,1,1).

2. Tweening

Tweening is easier! I don't really need to... explain. HUH.

local button
local ts = game:GetService("TweenService")
local lastTween = nil
local function ColorTween(c,second)
	if lastTween then
		lastTween:Cancel()--Stop the last tween, similar to the runningId
	end
	local establishedInfo = TweenInfo.new(second)--Add some styles and directions...
	local createdTween = ts:Create(button,establishedInfo,{BackgroundColor3 = c})
	lastTween = createdTween
	createdTween:Play()
end

The code block

if lastTween then
	lastTween:Cancel()
end

Does the same thing as the

if runningId ~= now then return nil end

1 comment

0

I am not a really um.. experienced coder so um, yeah um can you make it more simplified? x d

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