Hello! Scripts for a vampire hunting game, this one doesn't seem to work on mobile

So this is a script that triggers an interaction with another player (animations only.)

This works fine on PC, but it has come to my attention that mobile users aren’t able to get past the first step.
They are able to select the GUI button, so it isn’t an issue of sizing. From what it looks like, they can’t select the humanoid part of the other player to trigger the interaction.

Any help would be much appreciated, script below!

-- local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local toggled = false
local player = game:GetService("Players").LocalPlayer
local confirm = game.ReplicatedStorage:WaitForChild("ConfirmBite")

	if not toggled then
		toggled = true
		script.Parent.BorderColor3 = Color3.new(255,0,0) --shows that the button/ability is toggled. If you want to remove or change this it will not affect the script, so feel free. 
	else if toggled then
		toggled = false
			script.Parent.BorderColor3 = Color3.new(255,255,255) -- change this too if you change the way to show toggle

UserInputService.InputBegan:Connect(function(input, gpe)
	if not gpe and input.UserInputType == Enum.UserInputType.MouseButton1 and toggled then 
		local ray = camera:ScreenPointToRay(input.Position.X, input.Position.Y, 0) --this and the next line find what the player is clicking on.
		local part = workspace:FindPartOnRay(Ray.new(ray.Origin, ray.Direction * 500)) -- this number (def. 50) is the distance that a player can be clicked on from.
		if part.Parent:FindFirstChild("Humanoid") then --this checks if the user is clicking on a character
			local character = part.Parent
			local target = game.Players:GetPlayerFromCharacter(character)
			script.Parent.BorderColor3 = Color3.new(255,255,255)
			toggled = false
				--adding this just so it doesn't spam output with errors (which is fine). if you wanna add a message such as "Must Click Player" when you click something that isn't a player, do it here.

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

I believe the issue is because in your InputBegan event, you are only checking if the player clicked the left mouse button, there’s nothing that checks if the player touched their screen. Try changing the if statement from

if not gpe and input.UserInputType == Enum.UserInputType.MouseButton1 and toggled then 


if not gpe and (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch) and toggled then 

The 2nd thing I added to the condition will check if a touch screen input has been triggered. I placed them in brackets to make sure nothing goes wrong because there’s an or instead of an and, which may mess up the statement.

1 Like

Thank you! This helped a lot!

Finishing up the character count ignore this

Anytime! If you have any more issues don’t be afraid to make another post!