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

Why is the GUI not showing for certain devices?

Asked by 5 years ago
Edited 5 years ago

This script is supposed to open a GUI for a shop, but It doesn't work. Also the script is supposed to open up a different shop dependent on what device you're on. So a phone will open shop 2 while a PC opens shop1.

script.Parent.Touched:connect(function(part)
    local plr = game.Players:GetPlayerFromCharacter(part.Parent)
        if game:GetService("UserInputService").TouchEnabled == true then
            if plr then
                if plr.PlayerGui.Shop2.Enabled == false then
                plr.PlayerGui.Shop2.Enabled = true
                print("Shop Opened")

        else
            if plr then
            if plr.PlayerGui.Shop1.Enabled == false then
            plr.PlayerGui.Shop1.Enabled = true
            print("Shop Opened")
            end
            end
            end     
        end
    end
end)

1 answer

Log in to vote
1
Answered by 5 years ago

When you do game:GetService("UserInputService").TouchEnabled you're trying to see if the server is using a device with a touch screen, but that's not possible. So you have to use a RemoteFunction to let the server communicate with the players, then let the server ask the player who touches the brick, and let the player respond back through a RemoteFunction.

Add a RemoteFunction into ReplicatedStorage named "GetTouchEnabled"

Then in your script put:

script.Parent.Touched:Connect(function(part)
    local plr = game.Players:GetPlayerFromCharacter(part.Parent)

    if plr then
        local TouchEnabled = game.ReplicatedStorage:WaitForChild("GetTouchEnabled"):InvokeClient(plr)

        if TouchEnabled == true then
            print(TouchEnabled)
            if plr.PlayerGui.Shop2.Enabled == false then
                plr.PlayerGui.Shop2.Enabled = true
                print("Shop Opened")
            end
        else
            print(TouchEnabled)
            if plr.PlayerGui.Shop1.Enabled == false then
                plr.PlayerGui.Shop1.Enabled = true
                print("Shop Opened")
            end
        end
    end
end)

And put a LocalScript in StarterGui with the source:

local RF = game.ReplicatedStorage:WaitForChild("GetTouchEnabled")

function RF.OnClientInvoke()
    return game:GetService("UserInputService").TouchEnabled
end
0
Thanks a lot. Also I appreciate you actually telling me why it's not working for next time. kittonlover101 201 — 5y
Ad

Answer this question