How to make it so when a player is sat they can't jump

If it’s in the starter player scripts it affects to every single seat, which I don’t want. I only want the script on select seats.

try my code above then check if it works

That one also doesn’t work, sorry.

You can make it select certain seats through your code, it wouldn’t affect them all unless you made it. An example of doing this would be naming the seats you want it to affect something like “AffectedSeats”.

Then you can just scan the workspace for all of those seats:

Example
local localPlr = game:GetService("Players").LocalPlayer
    local PlayerModule = require(localPlr.PlayerScripts:WaitForChild("PlayerModule"))
    local Controls = PlayerModule:GetControls()

for i, v in pairs(workspace:GetChildren()) do
	if v.Name == "AffectedSeats" and v:IsA("Seat") then
		v.Touched:Connect(function()
			local Humanoid = v.Occupant 
		    if Humanoid == localPlr.Character.Humanoid then
		        Controls:Disable()
		    end
		end)
	end
end

You have a ton of control over what you are doing and that is just one method for it but there are plenty of others. I wouldn’t recommend a Touched event for this though you could just check if the Occupant value has changed.

wait a minute

local plrserv = game:GetService("Players")
Seat.Touched:Connect(function(hit)
       local plr = plrserv:GetPlayerFromCharacter(hit.Parent)
       local Occupant = Seat.Occupant

        Occupant = plr.Name
        if Occupant.Character then
              Occupant.Character:FindFirstChild("Humanoid").JumpPower = 0
         end
end)

there is no one occupanting the seat so thats why its nil

Are you still encountering Issues?

Yes. With both of the scripts you and darth gave me, when I go to test them they don’t work.

try it again for now and if it works please let me know

I went ahead and set up an example place for you to check out. It includes code for enabling/disabling player movement. It also checks for “AffectedSeats” and makes it so players can’t leave those by jumping. Alternatively, a player would be stuck like this until you re-allow them to jump so I added a leave seat button when you sit on an affected seat. You should be able to easily reference all of the code in this place and implement/use it how you need to in your game.

NoJump_Seat.rbxl (26.6 KB)

The green seat, a player can leave. Red seats require pressing the button. Disabling the button is extremely easy and is just a reference for if you want to make a player leave the seat later on.

Thanks, I’ll go and check it out.

here is a code

local Players = game:GetService("Players")

Seat.Touched:Connect(function()
     local curplr = nil
     if Seat.Occupant ~= nil then
         local humanoid = Seat.Occupant
         local char = humanoid.Parent
         local plr = Players:GetPlayerFromCharacter(char)
         if plr then
             local Hum = plr.Character:FindFirstChild("Humanoid")
             print(plr.Name.." Is the occupant")
             Hum.JumpPower = 0
             curplr = plr
             print(curplr.Name)
         end
     end
end)

I really don’t understand why this isn’t working for me… It’s working fine in your place but when I test it in my place it doesn’t work
I even copied and pasted the same seats and scripts in the exact same location over to my game and it still didn’t work.

Do you have any other scripts that check if the player has touched a seat, or mess with the characters .Touched or Jump events?

u tried my code right? 30charchar

“Seats” isn’t a roblox global, it would never do that. It doesn’t affect every single seat if it’s in starter player scripts. It still only affects the seats you specify. You’re not supposed to have localscripts in workspace and it’s better if you don’t have scripts there either.

There are two other services for that:
ServerScriptService
StarterPlayerScripts

And you should not used touched for this because the “Occupant” property is literally already a thing.

That being said, this code should work:

local CollectionService = game:GetService("CollectionService")
local Seats = CollectionService:GetTagged("Seat")

for _, seat in ipairs(Seats) do
    seat:GetPropertyChangedSignal("Occupant"):Connect(function(humanoid)
        humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
        humanoid.JumpPower = 0
    end)
end

Make sure you tag all seats with the tag “Seat” beforehand though. Also, this script goes in ServerScriptService.

1 Like

How do I “tag” the seats? Do I need a plugin to do it?

Yea, there’s a plugin named Tag Editor which you can use to tag them.
https://www.roblox.com/library/948084095/Tag-Editor

I tagged the seats, put this local script in the SSS. Went to test it and… it didn’t work. :frowning:

Was there an error? Also, try this and see if the prints work:

local CollectionService = game:GetService("CollectionService")
local Seats = CollectionService:GetTagged("Seat")
table.foreachi(Seats, print) -- see what this prints

for _, seat in ipairs(Seats) do
    seat:GetPropertyChangedSignal("Occupant"):Connect(function(humanoid)
        print(humanoid, 'touched seat') -- see if this prints
        humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
        humanoid.JumpPower = 0
    end)
end

No nothing prints. (30 charrrs)

If nothing prints in the first one, that probably means you didn’t tag the seats properly.

try adding this:

print(table.getn(Seats))

after the table.foreachi.