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)
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