Hello, I’ve been working on animating my overheadgui and I reached a point where the call script is doing as it should, but my issue is with my handler.
IsGradientEvent.OnServerEvent:Connect(function(player, IsGradient)
local char = player.Character or player.CharacterAdded:Wait()
local header = char:FindFirstChild("OverheadGui")
local gradSELECT = header.Label:WaitForChild("SelectedPreset")
local gradSELECT2 = header.Label3:WaitForChild("SelectedPreset")
local gradchange = header.Label:WaitForChild("UIGradient")
local gradchange2 = header.Label3:WaitForChild("UIGradient")
-- Animation handle
local button = gradchange
local button1 = gradchange2
local gradient = button
local gradient1 = button1
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(2, Enum.EasingStyle.Circular, Enum.EasingDirection.Out)
local ti1 = TweenInfo.new(2, Enum.EasingStyle.Circular, Enum.EasingDirection.Out)
local offset1 = {Offset = Vector2.new(1, 0)}
local offset2 = {Offset = Vector2.new(1, 0)}
local endingPos = {Offset = Vector2.new(-1,0)}
local create = ts:Create(gradient, ti, offset1)
local create1 = ts:Create(gradient1, ti1, offset2)
local createRev = ts:Create(gradient, ti, endingPos)
local create1Rev = ts:Create(gradient1, ti1, endingPos)
local startingPos = Vector2.new(-1, 0) --start on the right, tween to the left so it looks like the shine went from left to right
local addWait = .005 --the amount of seconds between each couplet of shines
print(IsGradient)
gradient.Offset = startingPos
gradient1.Offset = startingPos
gradchange.Color = (GradientPresets[gradSELECT.Value])
gradchange2.Color = (GradientPresets[gradSELECT2.Value])
local connection
local function animate()
create:Play()
create.Completed:Wait() --wait for tween to stop
createRev:Play()
create1:Play()
create1.Completed:Wait() --wait for tween to stop
create1Rev:Play()
end
if IsGradient == true then
connection = RunService.Heartbeat:Connect(animate)
elseif IsGradient == false then
gradchange.Color = (GradientPresets["Default"])
gradchange2.Color = (GradientPresets["Default"])
connection = RunService.Heartbeat:Connect(animate)
connection:Disconnect()
end
Obviously, I know this is wrong. There’s been a bug where it’ll overlap the animation effect, where it’s unable to actually break that loop once the true condition is broken.
The general idea is, if toggled → selected gradient preset is seen by the server, converts it into a string and sets the .Color to the Value that is stored in a table. (These two components are working just fine.)
My issue is once that is passed and applied to the textlabel, the color shows and the animation is ran perfectly fine on the first run through. But, when you try to toggle, ideally it would set to the colorsequence to (essentially just 1,1,1) and disabled the animation loop from running so when clicked again, it’ll apply itself…again. I’ve tried so many different angles and this has been the only one that has been able to yield…relatively ok results.
I’m struggling with finding a way to break a loop that needs to run continuously to apply the effect.
I’m not sure what to set my conditional boolvalues to, in the sense what they need to call once either true or false is sent to the server. It’ll toggle between the colors and plain white – just won’t stop trying to run the animation loop. I’ve tried sticking conditionals inside the function but that hasn’t yielded much luck.