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)
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)
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)
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.