How to make a PC User only seat

Just tested this. This should work

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

local TargetSeat = workspace.PCOnly

TargetSeat.ChildAdded:Connect(function(Child)
	if Child:IsA("Weld") and Child.Name == "SeatWeld" then
		if UserInputService.TouchEnabled then
			local Character = Player.Character
			local Humanoid = Character:WaitForChild("Humanoid")
			task.wait(0.1)
			Humanoid.Sit = false
		end
	end
end)

Store this inside the StarterPlayerScripts

Put this in a Script inside the seat with Script.RunContext set to client.

local seat = script.Parent

local UserInputService = game:GetService("UserInputService")
if UserInputService.TouchEnabled and (not UserInputService.KeyboardEnabled) and (not UserInputService.MouseEnabled) then
	seat.Disabled = true
elseif (not UserInputService.TouchEnabled) and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
	seat.Disabled = false
end

This way is better than some of the other solutions because it doesn’t ever let mobile users sit and doesn’t kick out mobile users. Instead, it never lets mobile users sit in the first place.

It almost works. The issue is when a PC-user sits on the seat then the mobile user is allowed to sit on it for some reason…?

Do you know why?

Sadly didn’t work at all… Don’t know why

I think I found a way that seems to work for me.

First, put in Normal Script in the seat you want, then put in the following code:

script.Parent.Changed:Connect(function()
	if script.Parent.Occupant then
		local player = game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Occupant.Parent)
		if player then
			game:GetService("ReplicatedStorage").PlayerOnMobile:FireClient(player)
		end
	end
end)

game:GetService("ReplicatedStorage").PlayerOnMobile.OnServerEvent:Connect(function(player, IsMobile)
	if IsMobilbe == false then
		print(player.Name.." Is on PC")
		-- Code here
	elseif IsMobile == true or IsMobile == nil then
		print(player.Name.." Is on Mobile")
		local humanoid = player.Character:FindFirstChildWhichIsA("Humanoid")
		if humanoid then
			humanoid.Jump = true
		end
	end
end)

Next, Create a RemoteEvent in ReplicatedStorage called PlayerOnMobile (Or any other name, but the script has to be changed to reflect the new name).

Then, create a LocalScript, call it any name you want, and place it in StarterPlayer > StarterPlayerScripts. Put this code in the LocalScript:

local replicatedstorage = game:GetService("ReplicatedStorage")
local userinput = game:GetService("UserInputService")

replicatedstorage.PlayerOnMobile.OnClientEvent:Connect(function()
	if userinput.TouchEnabled == true and userinput.KeyboardEnabled == false and userinput.MouseEnabled == false then
		replicatedstorage.PlayerOnMobile:FireServer(true)
	elseif userinput.TouchEnabled == false and userinput.KeyboardEnabled == true and userinput.MouseEnabled == true then
		replicatedstorage.PlayerOnMobile:FireServer(false)
	end
end)

Here’s a summary of how it works: When a player sits on the seat, It gets the player from the character that is sitting on that seat using Players:GetPlayerFromCharacter()

It then fires the RemoteEvent named PlayerOnMobile in ReplicatedStorage, which goes to the local script in the player’s PlayerScripts. Over there, it checks if they are on mobile or not, by checking its KeyboardEnabled, MouseEnabled, and TouchEnabled values on UserInputService, and then fires the RemoteEvent with either a true if they are on mobile, or false if they are on PC.

Back on the Script, it checks if the IsMobile value is false or true. If it is false, you can run code such as to open a Gui. But if it’s true, then it changes the Jump value in the player’s humanoid to true, which removes them from the seat.

I tried it myself and it worked, so I hope it works for you :slight_smile:

No idea if my idea is possible, but add some sort of GUI for mobile and check the StarterGui (if that’s where the mobile GUI is) to determine if player is on PC or mobile

Huh that’s strange. The problem might be that the seat gives network ownership to the character sitting in it which somehow allows the disabled property to replicate from the sitting player’s client to the server then to the other clients.

Try this code:

local UserInputService = game:GetService("UserInputService")

local seat = script.Parent

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if UserInputService.TouchEnabled and (not UserInputService.KeyboardEnabled) and (not UserInputService.MouseEnabled) then
		seat.Disabled = true
	elseif (not UserInputService.TouchEnabled) and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
		seat.Disabled = false
	end
end)

I’m not exactly sure what is causing the problem in your video, but the code above resets the disabled property every time someone enters or leaves the seat so it’s basically guaranteed to work even if it might not be the cleanest way to do that. (Make sure it’s in a Script set to local run context inside the seat.)

Seems like there is a problem I found with the Script…

In-order to get out of the piano you click on the Red Exit button and if you jump nothing happens so sadly your script doesnt work on the piano but on seats it does…

I didn’t catch what you mean “Set to local?”

I don’t see any local thingys here

image_2023-01-04_215313271

1 Like

Ah sorry, I mean client.

ok, ill try and fix it and hope it works

Edit: maybe simply not show the GUI if the player is mobile

that would make it worse because then the player cant get out then needs to reset or leave the game

That lets the mobile user go on the piano seat one time then it doesnt allow them to go on it again but on someones pov it just kinda breaks

Oops, I meant to add an initial set:

local UserInputService = game:GetService("UserInputService")

local seat = script.Parent

if UserInputService.TouchEnabled and (not UserInputService.KeyboardEnabled) and (not UserInputService.MouseEnabled) then
	seat.Disabled = true
elseif (not UserInputService.TouchEnabled) and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
	seat.Disabled = false
end

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if UserInputService.TouchEnabled and (not UserInputService.KeyboardEnabled) and (not UserInputService.MouseEnabled) then
		seat.Disabled = true
	elseif (not UserInputService.TouchEnabled) and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
		seat.Disabled = false
	end
end)

Let me test something on studio really fast and I might have a better solution.

I tested this in studio, it seemed to work:

local seat = script.Parent

local shouldBeDisabled
do
	local UserInputService = game:GetService("UserInputService")
	if UserInputService.TouchEnabled and (not UserInputService.KeyboardEnabled) and (not UserInputService.MouseEnabled) then
		shouldBeDisabled = true
	elseif (not UserInputService.TouchEnabled) and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
		shouldBeDisabled = false
	end
end

seat.Disabled = shouldBeDisabled
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	seat.Disabled = shouldBeDisabled
end)

(Script with client run context in a seat)

The above are super inefficient. I recommend using my code as seen below:

-- LocalScript

local UserInputService = game:GetService("UserInputService")
local PlayerService = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local CanPlayPianoEvent: RemoteEvent = ReplicatedStorage:WaitForChild("CanPlayPianoEvent")

if UserInputService.MouseEnabled and UserInputService.KeyboardEnabled and not UserInputService.TouchEnabled then
	CanPlayPianoEvent:FireServer(true)
else
	CanPlayPianoEvent:FireServer(false)
end

-- ServerScript

local PlayerService = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Seat: Seat = nil

local CanPlayPianoEvent = Instance.new("RemoteEvent")

CanPlayPianoEvent.Name = "CanPlayPianoEvent"
CanPlayPianoEvent.Parent = ReplicatedStorage

CanPlayPianoEvent.OnServerEvent:Connect(function(player, isDesktop)
	player:SetAttribute("CanPlayPiano", isDesktop)
end)

Seat:GetPropertyChangedSignal("Occupant"):Connect(function(humanoid: Humanoid)
	local Character = humanoid.Parent
	local Player = PlayerService:GetPlayerFromCharacter(Character)

	if Player and Player:GetAttribute("CanPlayPiano") then
		-- play the piano and such
	else
		print("Player cannot play piano as they don't have a keyboard and mouse!")
	end
end)

Basically, we have a local script that checks if the player is playing on a desktop, and if so, we fire an event with a boolean. On the server script, we listen to that event and receive the boolean. We then create an attribute on the player called CanPlayPiano which indicates if the player can play the piano or not. After this, we listen to the Occupant property changing on the seat. When it changes, we get the player who sat in the seat, and then we check if the player exists and the CanPlayPiano attribute is true. If the conditions are met, you can run your code that makes you play the piano. If both of the conditions are not met, then we will print that the user is not playing on the desktop and therefore cannot play the piano.

Your server script should be inside the part, and your local script should be inside StarterPlayerScripts. In your server script, change Seat to the path of your part.

same issue again… dont know why this is happpening

Is the ServerScript in the same script or do I have add a seperate Script for the --Server Script?

Oh and was I suppose to do it like this? Or leave it as nil
image

You must split them into two as said, everything below -- ServerScript should be placed in a Script, and everything below -- LocalScript should be in a LocalScript excluding the server script.