I’ve been trying to make a script that grabs the player’s device type and kicks them if they use a certain device.
For some reason kicking doesn’t seem to work even though printing the message does, could this be a problem with the kicking line?
Cnsle = game:GetService("UserInputService").GamepadEnabled
Mbile = game:GetService("UserInputService").TouchEnabled
Dsktp = game:GetService("UserInputService").KeyboardEnabled
function devices(player)
if Cnsle == true then
print("Console player joined")
player:Kick("Consoles are not currently supported. All devices will be supported in the near future!")
elseif Mbile == true then
print("Mobile player joined")
player:Kick("Mobile is not currently supported. All devices will be supported in the near future!")
elseif Dsktp == true then
print("Desktop player joined")
player:Kick("Desktops are not currently supported. This is a test message")
end
end
game.Players.PlayerAdded:Connect(devices())
Also before someone goes and tells me “There’s a way to do this without scripting”, I am aware and adding this to let all devices know that I am working on support for them while getting visits from them.
You must access UserInputService from a client script. So you’ll want to consider a RemoteEvent for that. In addition, remove the parathesis in “devices()” as you are calling the function (not connecting it).
As haz stated, inputService is client sidded. Also, why connect functions like that?
Here is a better way to do this, for the client. Place in a clientSidded area. (StarterGui, StarterPlayer, Camera, Etc)
local uis = game:GetService("UserInputService")
local console,mobile,desktop = uis.GamepadEnabled,uis.TouchEnabled,uis.KeyboardEnabled
if console or mobile or desktop then
game.Players.LocalPlayer:Kick("Your device is not supported yet.")
end
Also, I highly dont recommend doing this as thats a horrible tactic to do for visits, + thats how you get disliked. Its WHY you disable them, and not just make a script like this. Just make an announcement once its ready to be played on that device, and re-enable it in game settings.
I’m not hating on you at all, I think the premise of device detection is very creative and difficult, but if all devices are allowed to join but specific ones are kicked, because they’re not supported, isn’t it a little redundant, when they have no idea if they can play or not??
Also, here’s a demo I made almost a year ago, maybe what you’re looking for!
I should’ve made it more clear that it wasn’t really a “tactic” for visits. I have plans for more uses for this script like adding device icons above heads and redirecting players to device testing servers. This script is sort of the first stage of that.
But thank you for the tips (also @HazCreatez). I will test these and let you know if I’m having issues.
You need to run this code via a Client Script. Another thing you could do is modify the game via your “Game Settings” inside Roblox Studio. (Which is way easier if you don’t want to check if via Scripts) This can be done via Game Settings > Basic Info > Playable Devices.
> >
Alright, No problem. I have made a simplified version of the Script for you. Let me know if it works! (Create a Script inside ReplicatedFirst and name it anything you want, Name it “SupportController” if you don’t want to be confused)
-- Services
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
-- Variables
local LocalPlayer = Players.LocalPlayer
local IsMobile = UserInputService.TouchEnabled
local IsConsole = UserInputService.GamepadEnabled
local IsDesktop = UserInputService.KeyboardEnabled
-- Optional, Waits for the game to load
if not game.Loaded then
game.Loaded:Wait()
end
-- Checking
if IsMobile or IsConsole or IsDesktop then
LocalPlayer:Kick("\nThere's no support for either Mobile, Console, or PC.\nPlease, Come back in the near future!")
end
I don’t think that’s the problem. You can’t Fire events in normal Scripts and the LocalScript doesn’t seem to be working in Workspace.
Right now I have below in a LocalScript and it doesn’t do anything.
local event1 = game.ReplicatedStorage.DeviceRead
local player = game.Players.LocalPlayer
game.Players.PlayerAdded:connect(function(player, event1)
if game.Loaded then
event1:FireServer()
else
game.Loaded:Wait()
end
end)
Cnsle = game:GetService("UserInputService").GamepadEnabled
Mbile = game:GetService("UserInputService").TouchEnabled
Dsktp = game:GetService("UserInputService").KeyboardEnabled
function devices(player)
if Cnsle == true then
print("Console player joined")
player:Kick("Consoles are not currently supported. All devices will be supported in the near future!")
elseif Mbile == true then
print("Mobile player joined")
player:Kick("Mobile is not currently supported. All devices will be supported in the near future!")
elseif Dsktp == true then
print("Desktop player joined")
player:Kick("Desktops are not currently supported. This is a test message")
end
end
game.Players.PlayerAdded:Connect(devices)
local event = game.ReplicatedStorage.DeviceRead
local UIs = game:GetService("UserInputService")
local console, mobile, desktop = UIs.GamepadEnabled, UIs.TouchEnabled, UIs.KeyboardEnabled
local function DeviceCheck()
if console or mobile or desktop then
game.Players.LocalPlayer:Kick("It seems your device is not supported yet. You will be redirected to a test server in 10 seconds")
print("Un-Supported device joined.")
end
end
event.OnClientEvent:Connect(DeviceCheck)
ServerScript (in SSS)
local event = game.ReplicatedStorage.DeviceRead
local Players = game.Players
local function onPlayerAdded(player)
event:FireClient(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
I have found a simple solution which I should’ve tried at the start. Thank you to everyone in the replies who helped, it was appreciated!
ServerScript:
local UIs = game:GetService("UserInputService")
local console, mobile, desktop = UIs.GamepadEnabled, UIs.TouchEnabled, UIs.KeyboardEnabled
function devtype(player, console, mobile, desktop)
if console or mobile or desktop then
else
player.CharacterAdded:Wait()
player:Kick("Consoles and Mobile devices are currently not supported, I am working on support for both of these devices...")
print("Un-Supported device kicked.")
end
end
game.Players.PlayerAdded:Connect(devtype)