As the title says, .OnClientEvent is not working for my script to detect what device each player is on, and then change the text to either Click or Tap to open
Server script in SSS
while true do
wait(1)
if game:GetService("UserInputService").TouchEnabled and game:GetService("UserInputService").MouseEnabled == false then
game.ReplicatedStorage.IsMobile:FireAllClients()
print("Mobile")
while true do
wait(1)
if game:GetService("UserInputService").TouchEnabled == false and game:GetService("UserInputService").MouseEnabled == true then
game.ReplicatedStorage:WaitForChild("IsPC"):FireAllClients()
print("PC")
end
end
end
end
Local script in Billboard Gui Text Label
while true do
wait(1)
game.ReplicatedStorage.IsMobile.OnClientEvent:Connect(function(Player)
script.Parent.Text = "Tap to Open!"
print("Mobile2")
end)
end
while true do
wait(1)
game.ReplicatedStorage.IsPC.OnClientEvent:Connect(function()
script.Parent.Text = "Click to Open!"
print("PC2")
end)
end
Not getting any errors, and PC2 or MOBILE2 are not printing
sorry if my scripting is bad I am kind of a noob to scripting
Hey! Your problem is that you are trying to access UserInputService on the server which is not possible.
Therefore just do this in the localscript:
local UserInputService = game:GetService("UserInputService")
if UserInputService.TouchEnabled and not UserInputService.MouseEnabled then
-- Mobile
end
if not UserInputService.TouchEnabled and UserInputService.MouseEnabled then
-- PC
end
I put the local script in the TextLabel, and nothing happened, even using prints
local UserInputService = game:GetService("UserInputService")
if UserInputService.TouchEnabled and not UserInputService.MouseEnabled then
script.Parent.Text = "Mobile"
end
if not UserInputService.TouchEnabled and UserInputService.MouseEnabled then
script.Parent.Text = "PC"
end
local scripts do not work in workspace. Instead, put a localscript in starterGui and do this:
local UserInputService = game:GetService("UserInputService")
if UserInputService.TouchEnabled and not UserInputService.MouseEnabled then
game.Workspace.SmallGift.BillboardGui.TextLabel.Text = 'mobile'
end
if not UserInputService.TouchEnabled and UserInputService.MouseEnabled then
game.Workspace.SmallGift.BillboardGui.TextLabel.Text = "PC"
end