Asset Locked Seat - Not working

Hi, so I’ve made a script that basically jumps anyone who is sitting, if they don’t own a certain asset.

The script isn’t working, at all. Help is greatly appreciated!

local Seat = script.Parent
local MarketPlaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local PlayerOwnsAsset = MarketPlaceService.PlayerOwnsAsset

game.Players.PlayerAdded:Connect(function(player)
	Seat.Changed:Connect(function()   
		if Seat.Occupant ~= nil then
			local PlayerToJump = game.Players:FindFirstChild(Seat.Occupant.Parent.Name)
			local Character = PlayerToJump.Character or PlayerToJump.CharacterAdded:Wait()
			Players.PlayerAdded:Connect(function (player)
				local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketPlaceService, player, shirtid)
				if doesPlayerOwnAsset then
					print(player.Name .. " owns the item, and has been allowed to sit.")
				else
					print(player.Name .. " doesn't own the item, and has been jumped.")
					wait(.1)
					Character.Humanoid.Jump = true
				end
			end)
		end
	end)
end) 

Note: this script wasn’t entirely wrote by me. I took bits from developer.roblox.com, other devs on the devforum, such as how to detect a player sitting, ect. I just don’t know if I’ve pieced it together quite right.

Okay so firstly:
You do not need a seat.Changed event connection for every player in game

Secondly:
You connect a second player added event? I’m a bit lost. So a player hops in the seat then it makes a connection on all new joined players and makes them jump randomly

Seat.Changed:Connect(function()   --Only needs connecting once
    if Seat.Occupant ~= nil then
		local PlayerToJump = game.Players:FindFirstChild(Seat.Occupant.Parent.Name)
		local Character = PlayerToJump.Character --If they are already in the seat the character is definitely loaded 
		local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketPlaceService, player, shirtid)
		if doesPlayerOwnAsset then
			print(player.Name .. " owns the item, and has been allowed to sit.")
		else
			print(player.Name .. " doesn't own the item, and has been jumped.")
			wait(.1)
			Character.Humanoid.Jump = true
		end
	end
end) 
1 Like

I’m a bit confused too.

What’s meant to happen (in order):

  • A player sits down
  • If the player doesn’t own that asset, it jumps them

I know there are two Players.PlayerAdded, I removed it after posting.

Can you show me what the final script should look like? I’m really confused.

I want to add to this that changing humanoid.Jump wont make a player jump you have to change humanoid.Sit to false

Thanks, I’ll have a go at that and see if it works.

Making it jump does make you get out a seat doesn’t it?

It might now, but when I tried to do something like this a year ago I remember having to use sit = false. jump may work now though I’m not sure

Theres no reason for the player added events

seat:GetPropertyChangedSignal('Occupant'):Connect(function()
  local occupant = seat.Occupant
  if occupant then
    local char = occupant.Parent
    local player = Players:GetPlayerFromCharacter(char)
    if player then
      local y, owns = pcall(MarketplaceService.PlayerOwnsAsset, MarketplaceService, player, shirtId)
      if not y or not owns then
        occupant:ChangeState(Enum.HumanoidStateType.Jump)
      end
    end
  end
end)

You’re right I tested it

Seat.Changed:Connect(function()   --Only needs connecting once
    if Seat.Occupant ~= nil then
		local PlayerToJump = game.Players:FindFirstChild(Seat.Occupant.Parent.Name)
		local Character = PlayerToJump.Character --If they are already in the seat the character is definitely loaded 
		local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketPlaceService, PlayerToJump , shirtid)
		if doesPlayerOwnAsset then
			print(PlayerToJump.Name .. " owns the item, and has been allowed to sit.")
		else
			print(PlayerToJump.Name .. " doesn't own the item, and has been jumped.")
			wait(.1)
			Character.Humanoid.Sit = false
		end
	end
end) 

Where are we getting “player” from? It has a red line under player in player.Name

Edited code with fix player should be PlayerToJump

1 Like
local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
local PlayerOwnsAsset = MarketPlaceService.PlayerOwnsAsset

local AssetId = 0 --Change to ID of asset.

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		Humanoid.Seated:Connect(function(IsSeated, SeatPart)
			if IsSeated then
				local Success, Result = pcall(PlayerOwnsAsset, Player, AssetId)
				if (Success and (not Result)) or not Success then
					local SeatWeld = SeatPart:FindFirstChildOfClass("Weld")
					if SeatWeld then
						SeatWeld:Destroy()
					end
				end
			end
		end)
	end)
end) 

This would serve as a more general solution which would work for any Seat/VehicleSeat instance, you could additionally implement a check for the SeatPart’s name if necessary.