Question, Am I Over Loading This LocalScript? Vol.1

Hello, I’m making a GUI Button that Goes Down and Back up (And Changes Color). Here’s the Glitchy LocalScript:

local frame = script.Parent
local button = script.Parent.Parent
local function onButtonActivated()
	frame.BackgroundColor3 = Color3.fromRGB(150, 150, 150)
	button:TweenPosition(UDim2.fromScale(0.35,0.7),Enum.EasingDirection.In,Enum.EasingStyle.Sine, 0)
	task.wait(0.1)
	button:TweenPosition(UDim2.flocalromScale(0.35,0.68),Enum.EasingDirection.In,Enum.EasingStyle.Sine, 0)
    frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
    game.StarterGui.magnaIconTween.waitForChild("magnaIcon"):Clone().Position = UDim2.new(math.random(1,8)/10,0,1/10,0) -- This seems to be the problem.
end
button.Activated:Connect(onButtonActivated)

And Yes I was Clicking…
Also would it be safe to add another LocalScript to the Button?

  • You should make another LocalScript
  • Making More Localscript will mess up the button

0 voters

TextButtons listen for the MouseButton1Click event, not the Activated event for mouse button clicks.

Sorry, but the Button is the Outline ImageButton Thing.

ImageButtons use the same event when listening for mouse clicks.

But @NicholasY4815, i got

local function onButtonActavated()

from Roblox Documentation

Change it to this…

button.MouseButton1Click:Connect(onButtonActivated)

Sorry, @lilmazen1234 Still doesn’t Work.

Were you clicking multiple times or holding it down?

I was Clicking Many Times. :slight_smile: :slight_smile: @CipherFunctions

Try this, however, I doubt it’ll work.

local frame = script.Parent
local button = script.Parent.Parent
local connections = {}
local function onButtonActivated()
    connections["Activated"]:Disconnect()
    connections = {}
	frame.BackgroundColor3 = Color3.fromRGB(150, 150, 150)
	button:TweenPosition(UDim2.fromScale(0.35,0.7),Enum.EasingDirection.In,Enum.EasingStyle.Sine, 0)
	task.wait(0.1)
	button:TweenPosition(UDim2.flocalromScale(0.35,0.68),Enum.EasingDirection.In,Enum.EasingStyle.Sine, 0)
    frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
    game.StarterGui.magnaIconTween.waitForChild("magnaIcon"):Clone().Position = UDim2.new(math.random(1,8)/10,0,1/10,0) -- This seems to be the problem.
    connections["Activated"] = button.Activated:Connect(onButtonActivated)
end
connections["Activated"] = button.Activated:Connect(onButtonActivated)