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)
I just posted a bug report too xD… I’m an idiot
Thank you soooo much!