How do I make a Computer only Script

I can’t find a tutorial anywhere to make a “device only script” but I need a script that only affects PC/Computers and not Mobile, Xbox, etc.

The script/model below only works for PC and when enabled, it makes mobile players not be able to move because of it’s Custom Player movement.

BACKGROUND INFORMATION

For the script to work, you’re required to put the DevComputerMovementMode (in StarterPlayer) to Scriptable. That’s what I did and it works perfectly fine on PC, but on mobile, you can’t move even if you put the DevTouchMovementMode to DynamicThumbstick or others.

Better Character Movement - Roblox

2 Likes

You can use UserInputService.KeyboardEnabled to check if a player is on PC (locally) and if so, allow the local script to run.

1 Like

For example:

--//Services
local UserInputService = game:GetService("UserInputService")

--//Functions
if UserInputService.KeyboardEnabled then
	print("Player is on computer.")
	--//Run your code
end
1 Like

Oh, I just downloaded the module and this is how the local script should look like:

--// Original "Quake-Like" Movement System by Boatbomber
--// Modifications for a more complete movement system made by iGottic

--// Please set MovementMode in StarterPlayer to Scriptable
--// Only compatable with PC

--=========================================================================--
--=========================================================================--

local JUMP_POWER = 50 -- How much force is put into jumping
local GRAVITY = 125 -- Gravity. Changed on client to not intefere with server.
local JUMP_COOLDOWN = 1 -- The cooldown time between jumps. During cooldown, use cannot jump.

--=========================================================================--
--=========================================================================--

-- Refrain from changing the below code to keep it peformant and functional

local UIS,RS = game:GetService("UserInputService"), game:GetService("RunService")

if UIS.KeyboardEnabled then
	local Spring = require(script.SpringModule)
	local v3 = Vector3.new

	local Direction = Spring.new(v3())
	Direction.Speed = game.StarterPlayer.CharacterWalkSpeed * 0.85

	local Front,Side = v3(0,0,1),v3(1,0,0)
	local LastJump = 0

	local Player = game.Players.LocalPlayer
	local Humanoid

	local CalculatedJumpPower = JUMP_POWER * (GRAVITY/196.2)

	workspace.Gravity = GRAVITY

	local Alive = false

	UIS.InputBegan:Connect(function(Input,GP)
		if not GP and Input.UserInputType == Enum.UserInputType.Keyboard then
			--Handle movement

			if Input.KeyCode == Enum.KeyCode.W then
				Direction.Target = Direction.Target - Front

			elseif Input.KeyCode == Enum.KeyCode.S then
				Direction.Target = Direction.Target + Front

			elseif Input.KeyCode == Enum.KeyCode.A then
				Direction.Target = Direction.Target - Side

			elseif Input.KeyCode == Enum.KeyCode.D then
				Direction.Target = Direction.Target + Side
			end
		end

		if not GP and (Input.KeyCode == Enum.KeyCode.Space or Input.KeyCode == Enum.KeyCode.ButtonA) then
			-- Handle jumping
			if tick()-LastJump>= JUMP_COOLDOWN then
				Humanoid.Jump = true
				LastJump = tick()
			end
		end
	end)

	UIS.InputEnded:Connect(function(Input,GP)
		if not GP and Input.UserInputType == Enum.UserInputType.Keyboard then
			--Handle movement
			if Input.KeyCode == Enum.KeyCode.W then
				Direction.Target = Direction.Target + Front
			elseif Input.KeyCode == Enum.KeyCode.S then
				Direction.Target = Direction.Target - Front
			elseif Input.KeyCode == Enum.KeyCode.A then
				Direction.Target = Direction.Target + Side
			elseif Input.KeyCode == Enum.KeyCode.D then
				Direction.Target = Direction.Target - Side
			end
		end
	end)

	local function CharacterAdded(c)
		Humanoid = c:WaitForChild("Humanoid")
		Humanoid.JumpPower = CalculatedJumpPower

		Alive = true

		Humanoid.Died:Connect(function()
			Alive = false
		end)
	end

	Player.CharacterAdded:Connect(CharacterAdded)

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

	RS:BindToRenderStep("Walking", 100, function()
		if Alive then
			Player:Move(Direction.Position, true)
		end
	end)
end
2 Likes

Or , as an alternative, you can change Roblox settings for a game for computer only. No scripts needed.

I want mobile players to play aswell, since it’s an FPS game, it’ll lose an massive amount of players and revenue unfortunately.

So enable mobile and computer

That’s what I did, I also found the solution so thanks to @Katrist for the solution!