I’m not a pro scripter and most of the stuff I write on my own is very simple, and I can’t really figure this out, so basically I have a Sonic-type homing attack script a friend wrote for me, and originally it was mapped to the jump button but I changed it to E later.
That was simple enough, but now I also want Xbox players to experience my game and since the Homing attack is not bound to the jump button (since the double jump is bound to that) Xbox players simply can’t do the homing attack.
I would need the X button on the controller to do the homing attack while also keeping the E key for PC players.
I tried using a simple “Enum.KeyCode.E or Enum.KeyCode.ButtonX then” and while it did work for Xbox, it messed up the keyboard controls and every single key did the homing attack on keyboard.
This was my second attempt but this simply just didn’t work on Xbox.
My previous attempt did tell me that I could just copy paste the entire script into a second LocalScript and change the keybind in that script but it would be more organized if I did it all in one script, also I’m not sure if that would even work either since the same issues could appear as before where keyboard controls activate both scripts.
If anyone can help me with this, please do. Thanks!
I tried that single line from before and it just underlined the entire thing below it with orange, so I’ll try the wiki stuff again and update if it works or not.
Nothing seems to give an error except that “false” there.
Tried to put an “end” after that line to see if it fixes it but that didn’t do the trick either.
I know this is a lame solution but even when I asked a friend who knows programming we couldn’t find a solution to make this work with one script.
So here’s what I did which worked.
I basically copy pasted the script, named the one for the E key PC and the one for the X button XBOX and just changed the InputType and the button pressed in each script. That’s it.
Totally a better way to do this. What you can do is you can make a module that has the function, and then in one local script you can make an event connection for both, and call the function. Or, you could make a table full of keycodes in the module, and loop through the keycodes and see if the player pressed it, if so, fire the function. I hope you find this useful.
Nooooooo you can detect the user’s LastInputType and determine what controller type they have, then grab the keycode or GetKeysPressed(), loop through that and apply the action, or do @SomeFedoraGuy 's solution! Eitherway lol, glad you got it! Edit: you dont want multiple input threads running, it can cause multiple actions to happen if, per say, someone had their Xbox controller plugged in to pc, but they have joystick drift, then try to use keyboard, and both scripts activate!
Second Edit: If you plan on using the same logic, you can just change your PC script and use it by itself by doing
if input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.Gamepad1 and input.KeyCode == Enum.KeyCode.E or input.KeyCode == Enum.KeyCode.ButtonX then