How to make the 'Press any key button to start' work?

This removed the error in the output, however when I try and press a key it does not do anything.

Could you show us your code? It looks like it’s an issue with the way you fade out your GUI.

It is this code up here, just changed Keycode to KeyCode

You are aware that the code LowQualityDio provided only detects when a key is pressed right? Everyone assumed you already knew how to fade out the GUI, and just needed to know when to do so.

It might be my fading out script that messed up, give me some time to go over it

UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then

Oh sorry, where posted a form of that …
If that’s all you’re really looking for that should work.

There’s many ways to do this, personally I’d just yield my code until the condition(s) are met.

Example:

local uis = game:GetService("UserInputService");
local keyPressed = false;

local onInput = nil
onInput = uis.InputBegan:Connect(function(key, gp)
    if gp then return end;

    if key.UserInputType == Enum.UserInputType.Keyboard then
        keyPressed = true;
        onInput:Disconnect();
    end
end)

repeat
    task.wait();
until keyPressed

-- Code after to load,
-- For organization you could turn this part into a module or the part above,
-- You could make the next part a module then do something like "module.Start()"
-- But I think putting code below is easier

Hope this helps
Also do you need help with the tween?

Please do not do this, this is a horrible habit, yielding your code by using repeat wait() until is incredibly ineffecient, and it can easily be replaced by just putting the code into the event.

Which is why I said personally, I do that since I hate the look of having a giant piece of code wrapped in “InputBegan”, I’ve also seen no difference between the two (only in cases like this where you don’t want the game to start until that’s pressed)

The difference is how it affects the performance of the server, having to constantly call the wait function, and check if the condition is true, require much more processing power than just executing the code upon an event being triggered.

I’m pretty sure your client using task.wait() and a loop wouldn’t effect the server that majorly, or at all even, and with that logic no client loop or task.wait() is safe.

I also went in a studio and did multiple tests with this code, one with only 1 player using it, one with both and one with none, they all had similar results and the server was the same throughout all of them

You are indeed right about the client not affecting the server, I seem to have forgotten the context of this thread. Regardless however, all this means is that the Client is affected in place of the server.
And like I mentioned, you shouldn’t do this because it is bad practice, you won’t see any noticeable difference if you do this once or twice, but if you create an entire game, with countless instances of such programming, it will have a negative effect on your performance.

I know the dangers of constantly using loops like this, that’s why I mentioned this

That’s also why I mentioned using modules, you could load a module after that’s pressed that contains everything, I only say these because I find it annoying wrapping huge code inside something like that.

(edit) Looking back I didn’t specify changing out the loop with modules, I only commented it after the loop, my bad.

Even in cases such as the one provided in this thread, you shouldn’t yield the script in such a manner, it is still bad for performance. There are also many other ways of formatting your code that avoids the issue you have with this, one of those is as you mention: modules, or simply just a function call.

I’ve done it in games, there’s been no noticeable performance issue so you do you. And that’s another personal preference, I think having all the code in a separate module looks nicer than a function, keep in mind I’m only talking about huge code that waits for your input to continue/execute, not every function you have in a script. Please forgive me for editing so much


After using your help, I’ve made it work. Thanks all.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.