Local Script working on mobile but not working on pc? Help, this is so weird!

ContextActionService:BindAction(“Attack”, handleAttack, true, Enum.UserInputType.MouseButton2)

You can use a quick debug test here. Rebind it to right click just for now. Then test your tool if it works on PC then you know it is that line of code causing it. Since mobile cannot click i assume thats why the tool works there and not on PC. Test this out and get back to me!

3 Likes

Now that’s a problem, when i put it on mousebutton2 i can’t move my camera, context action service is bugged! But that is what happens.

2 Likes

It is not bugged. It is because you are removing roblox’s core handler. Example you are overwriting the camera now. So the camera handler is no longer a thing. Since it is binded to attack. But does the tool work?

1 Like

Yes, it works, only the camera that i can’t move, but for some reason i can’t attack, it may be because of the core handler camera thingy

1 Like

I recommend dropping the use of Context Action Service and rewriting your script to rely on UserInputService, here you will be able to detect when the player is Left Clicking. It will not override any of roblox’s functionality.

1 Like

But context action service creates mobile buttons, it are a lifesaver… well actually it can’t be that lifesaver when that happens…

1 Like

You can create your own mobile buttons i believe. I would suggest looking into that. All you would have to do is check when the UIS.InputChanged is connected. if it is mobile then parent a screenGui to the player. if it is not do nothing.

1 Like

i’m lazy to create my own mobile buttons tho lol

1 Like

Here is a link what i referenced above… If you are lazy then dont add mobile support. There is not much i can do besides saying reroute your Keybind to a Key on the keyboard. I do believe this community tutorial will help you as it supplies a lot, i did a quick run through of it and it looks pretty good! Take the opportunity to make this a learning experience for you! Mobile players are one of the core parts of Roblox games.

2 Likes

hm, i’m gonna try, gonna let you know if it works.

2 Likes

The solutions i can see here are;

  • Bind the usage of the item to another key Enum.Keycode.E or some other key
  • Bind and Unbind the Attack action when a usable is equipped or unequipped
  • Or doing what @McGamerNick said and ditching ContextActionService and making your own buttons

I would recommend doing your own buttons regardless, ContextActionService’s button configuration is limited

3 Likes

Fine… AAAAAAAAAAAAAAAAAAAAAAAA ok i’m designing my own buttons

I wish you the best of luck! You dont have to go all out. Just get a simple little prototype working even an image/ text button will do! Then later you can always adjust pre-launch.

1 Like

But seriously, there’s no other way of fixing this??

Unless you do what @uriel_Gamer444 said above. You will have to just make a simple text button then parent it to mobile. It is really easy to do. Shouldnt take more than 5 minutes. Then just check when the button is clicked then run the function of your Attack.

hmm, should i still use context action service then?

If do not want mobile players in your game then yes. But remember your tools wont work unless you switch to UserInputService. There is a more advance way of going about your Context Action Service without using tools. You would have to make your own HUD, store it to the player so you can reference it. And when the player attacks you can check which attack it is by seeing what you stored. But considering you do not wanna go through the struggle of adding your own buttons for mobile. I dont think itll be something you would take on

oke, that’s my response then, but there are millions of mobile players, so of course i want to make mobile support.

Check if player is on mobile using UIS.InputChanged. If they are on input.UserInputType == Enum.UserInputType.Touch then you just Clone your screengui of buttons and parent it to the player in player gui. Store this local script in StarterPlayerScripts.

1 Like

ContextActionService is really good, just have to know how to work with it

A possibility is Unbinding Attack for the tools function on equip and rebinding Attack on unequip

local ContextActionService=gamer:GetService("ContextActionService")
local Tool=script.Parent

local drinkFunction()
--Code that i don't wanna copypaste
end

Tool.Equipped:Connect(function()
ContextActionService:Unbind("Attack")
ContextActionService:BindAction("Drink", drinkFunction, false, Enum.UserInputType.MouseButton1)
end)


Tool.Unequipped:Connect(function()
ContextActionService:Unbind("Drink")
ContextActionService:BindAction("Attack", handleAttack, false, Enum.UserInputType.MouseButton1)
 --Create button to false cause you should still do custom buttons lol
end)
2 Likes