Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is checking if player is on mobile not working? (FilteringEnabled)

THE ONLY PART OF THE SCRIPT THAT IS BROKEN IS THE MOBILE CHECKER!

Basicly the script is supposed to open a gui. It works, but when I check for if the player is on mobile, it doesn't work. Any reason why? Thanks!

SCRIPT:

local RemoteEvent = game.ReplicatedStorage.Events.Shops

script.Parent.Touched:connect(function(hit)
    if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then
		local ismobile = game:GetService('UserInputService').TouchEnabled --Issue.

		if ismobile == true then
			RemoteEvent.Shop2Event:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
		else
			RemoteEvent.Shop1Event:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
		end
    end
end)

1 answer

✓ Accepted answer

###This is not working because UserInputService is client-side only. It does not exist on the server. You’ll have to use a RemoteFunction checking if the user is on mobile. You shouldn’t use UserInputService.TouchEnabled, as this is true if a user has a touch-screen computer.

3 comments

0

Now that I think of it, wouldn't a remote function be better?

0

Remote functions are for two way communications. Remote events send a request, and remote functions send a request and wait for a response. Use remote functions if you want to return data. In your case, you’d want to return if the player is on a mobile device.

0

I used a remote function and it works. So the script fires the function and it checks if the player is on mobile. Then the info returns to the script and tells the script if the player is on mobile or not.

This discussion is preserved as it was. New answers, comments, and votes are closed.