Button.Activated fired on join game?

Also, I did. I just edited the topic.

Nice okay, instead of Button.Activated, use Button.MouseButton1Click

Its cross platform… So that would break anything else I’ve set up.

Shouldn’t .Activated run on mouse click, tap, and selected with gamepad? Because my other buttons work.

Can you show a script so I can see

`local function startLevel(LevelNumber)
	Print("Run!")
end    

script.Parent.Parent.Parent.Parent.Overlay.StoryOverlay.StartGame.Activated:Connect(startLevel(1))`

I take it that it prints ‘Run’ by itself without clicking?

Yes it does, I’m starting to think that it’s an studio bug.

I think you need to check what the input is before printing, I’m testing it now and I’ll send you a script once finished

Why do my other buttons work then… They all work the exact same way. They are ctrl + c, ctrl + v…

I think I found the issue…
Can there be too many ‘.Activated’ in 1 script?

If it’s for the same button it could create issues

Nvm… It worked then didn’t.
I think its a bug.

So, I tested it with another button and it worked. Then I added (StartLevel(1)) – The number and it broke. I think its a bug with the number.

local function startLevel(inputObject,clickCount,LevelNumber)
	if inputObject.KeyCode == Enum.KeyCode.ButtonX or inputObject.KeyCode == Enum.UserInputType.MouseButton1 or inputObject.KeyCode == Enum.UserInputType.Touch then
		print("Run!")
	end
end    

script.Parent.Activated:Connect(function(inputObject,clickCount)
	startLevel(inputObject,clickCount,1)
end)

Its a bug with ‘:Connect’, There is a problem when you send data through them. Hence the reason my other buttons work.

Actually button activated doesn’t work for me at all

How so?
I seem to have it working pretty well now, just needed to add a few extra steps.

I don’t know, I’m actually getting pretty tired, I hope you find a solution though

Yea… Its a bug. A pretty pesky bug at that.

If I recall correctly, this is normal behavior. Doing something like guiButton.Activated:Connect(doThis()) would automatically call doThis() even if the Activated event did not fire (think of the parentheses after the function name as the function runner/starter). On the other hand, if you do something like guiButton.Activated:Connect(doThis), the doThis function will only be called when the Activated event fires.

Because of this, I don’t think there is a way you can directly pass a custom argument through :Connect(). What you can do, though, is create a variable somewhere inside the script, and then use that as a reference for your function.

Example:

local levelNumber = 1
local function startLevel()
    print(levelNumber)
end

guiButton.Activated:Connect(levelNumber)

Another alternative is to use an anonymous function. This way, you don’t need to use a variable as mentioned above.

Example:

local function startLevel(levelNumber)
    print(levelNumber)
end

guiButton.Activated:Connect(function()
    startLevel(yourArgumentHere)
end)
2 Likes