Checking For Device Works in Studio But Doesn't in Player

  1. What do you want to achieve? Keep it simple and clear!
    Change the text on a gui depending on device type

  2. What is the issue? Include screenshots / videos if possible!
    It works perfectly in studio but flat out dosent in roblox player

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried switching what it checks for and different ways of checking but everytime it works perfect and studio and doesnt in player

local UserInputService = game:GetService("UserInputService")

workspace.ChildAdded:Connect(function(hit)
	if game.Players:FindFirstChild(hit.Name) then
		UserInputService.InputBegan:Connect(function(input)
			print(1)
			if UserInputService.TouchEnabled then
				print(2)
				players:GetPlayerFromCharacter(hit).PlayerGui.Freeze.TextLabel.Text = ("Tap")
			end
		end)
	end
end)

If you change it to use CharacterAdded instead of doing workspace.ChildAdded, does it resolve the issue at all?

i.e.

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

UserInputService.InputBegan:Connect(function(input)
	print(1)
	if UserInputService.TouchEnabled then
		print(2)
		players:GetPlayerFromCharacter(hit).PlayerGui.Freeze.TextLabel.Text = ("Tap")
	end
end)		

or alternatively, if the local script doesn’t get reset when they die:

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer

local function CharacterAdded(char)
	UserInputService.InputBegan:Connect(function(input)
		print(1)
		if UserInputService.TouchEnabled then
			print(2)
			players:GetPlayerFromCharacter(hit).PlayerGui.Freeze.TextLabel.Text = ("Tap")
		end
	end)	
end

Player.CharacterAdded:Connect(CharacterAdded)

if Player.Character then
	CharacterAdded(Player.Character)
end
	

Unfortunately the same issue happened here and no errors show up ingame either

Is either 1 or 2 printing out in console?

Neither are printing in console in roblox player

If you add an additional print statement at the very top of the script, does it print out?
(Also, which variation of my code did you end up going with, the first one or the second one?)

I just did nothing and all of the sudden it worked no idea what changed or how it didnt work before but now it does

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.