Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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.

0
Now that I think of it, wouldn't a remote function be better? kittonlover101 201 — 5y
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. User#19524 175 — 5y
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. kittonlover101 201 — 5y
Ad

Answer this question