How to make a PC User only seat

What I want to achieve:

I’m trying to make a seat that only people that are playing on a computer can sit on and mobile users cant. (Basically what I’m saying is if a user that is playing on a computer they can stay on the seat with no problem but if a user is on a mobile device they automatically get out. but since I’m not good at scripting at all I don’t know how to do this)

What the issue is:

In my game I added Pianos and Mobile Users can’t use them properly because if they do they either get stuck because the exit button is out of their screen or they spam the notes which makes the other pianos break entierly until they stop spamming the notes (If someone spams a lot of notes on the piano the other pianos cant play a note because the audio is getting spammed basically forcefully stopping the other pianos audio (I have tried fixing this but nothing worked because I found NOTHING!)

What Solutions I have tried:

I have tried using this code (its a local script in the seat)

local UserInputService = game:GetService("UserInputService")
if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
return
elseif not UserInputService.TouchEnabled and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
	--Code goes here
end

But dont know what to put in the “–Code here” I have tried searching everywhere and tryed using a code that if you touch a part you jump or something like that but I don’t how scripting works so everything has failed and I really need help. What I’ve been thinking is “if someone that isn’t a PC User for example Player1 is a mobile user and Player2 is a PC user that Player2 is allowed to freely use the piano but Player1 can’t use the piano because they are one a Mobile Device” But again don’t know how to do this at all because it’s just very confusing…

Could someone possibly help?
I have tried listing every detail I can sorry if I missed some…

3 Likes

In the

--Code Goes here
spot you put,

  local char = game.Player.LocalPlayer.Character
   local hum = char:WaitForChild("Humanoid")
   local chosenseat = NameOfSeat -- Replace with your seat Example Workspace.Seat
   chosenseat:Sit(hum)

Alright I’ll see if that works

1 Like

For some odd reason it doesn’t work…?

local UserInputService = game:GetService("UserInputService")
if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
	return
elseif not UserInputService.TouchEnabled and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
	local char = game.Player.LocalPlayer.Character
	local hum = char:WaitForChild("Humanoid")
	local chosenseat = workspace.Piano.one.Bench.Seat -- Replace with your seat Example Workspace.Seat
	chosenseat:Sit(hum)
end

Do you know why?

That script doesn’t seem to prevent the player from sitting on it, rather determining a seat if they aren’t mobile.

2 Likes

Oh… My bad haha

How do I make it prevent the user from entering the seat if they are mobile? Because I don’t know how because I’m not good at scripting at all.

The code:

(local script)

local UserInputService = game:GetService("UserInputService")
if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
	return
elseif not UserInputService.TouchEnabled and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
	local char = game.Player.LocalPlayer.Character
	local hum = char:WaitForChild("Humanoid")
	local chosenseat = workspace.Piano.one.Bench.Seat -- Replace with your seat Example Workspace.Seat
	chosenseat:Sit(hum)
end

Try something like this

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

local chosenseat = workspace.Piano.one.Bench.Seat

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

Do I replace the whole entire script with that?

Yeah, try it and see if it works

Alright, I’ll tell you if it works.

1 Like

Sadly it didn’t work again.

Did you make the ‘chosenseat’ the right seat?

Do you want it where no seats in your game work if you are on mobile?

Have you put this?
Screen Shot 2023-01-04 at 10.18.06 am
Then you need to put a userinputsevice script.

Yeah I did.

I don’t want that all seats dont work if your on mobile I only want it specifically for these piano

1 Like

Put the ‘PCOnlyScript’ in starterplayerscripts

yeah but then he will have to put it as a function to call it.

Yeah I put it in “StarterPlayerScripts” and it still did not work.

I do not know much about scripting but you need to put the “PCOnlyScript” into the starterplayerscripts then you make a script that only lets pc players sit on it where the seat function is then see if that works.

As I said earlier

I’m not good at scripting at all.

I’m not sure how to do that…

Oh sorry I did not see that part.