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

Why is the GUI not showing for certain devices?

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

✓ Accepted answer

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

1 comment

0

Thanks a lot. Also I appreciate you actually telling me why it's not working for next time.

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