I’m looking to create a script that prevent users that don’t own a certain gamepass from accessing a vehicle. I’ve placed this code in a local script in the VehicleSeat itself.
local MarketplaceService = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer
local BoatSeat = script.Parent
local gamepassId = 14536719
local RegenButton = game.Workspace.SpawnBoatSign.SurfaceGui.RegenButton
RegenButton.MouseButton1Click:Connect(function()
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamepassId) then
else
BoatSeat.Disabled = true
end
end)
There aren’t any error messages but I am still able to sit in the seat and drive the vehicle despite not owning the gamepass.
From what I can see at first glance, it seems like the seat is only disabled if you click a button. Even if it did work, this doesn’t seem like a good approach, what if someone else clicks the button then you can sit in it?
localscripts dont run in workspace, and doing this via a localscript is a horrible idea since exploiters can just dump the script and completely bypass the gamepass and drive the boat
Another approach to this would be making this a ServerScript inside of the Seat and using the Changed event. Afterward, you can check the Occupant property on the seat (which returns the Humanoid) and you can check if they own the gamepass or not after that.
local MS = game:GetService("MarketplaceService")
local Seat = script.Parent.Seat
Seat.Changed:Connect(function(prop)
if prop == "Occupant" then
local humanoid = Seat.Occupant
local plr = game.Players:GetPlayerFromCharacter(humanoid.Parent)
if MS:UserOwnsGamePassAsync() then
-- insert code here
else
humanoid.Jump = true
humanoid.Jump = false
end
end
end)
local MarketplaceService = game:GetService("MarketplaceService")
local BoatSeat = script.Parent
local GamepassID = 14536719
local RegenButton = game.Worskspace.SpawnBoatSign.SurfaceGui.RegenButton
RegenButton.MouseButton1Down:Connect(function(Player)
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassID) then
return
else
BoatSeat.Disabled = true
end
end)
A few things: LocalScripts don’t work in Workspace, and/or LocalPlayer only works in LocalScipts. In addition, I would always use MouseButton1Down as opposed to MouseButton1Click!
local marketplace = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local seat = script.Parent
local seatEvent = seat:GetPropertyChangedSignal("Occupant")
local gamepassId = 0 --Change to ID of gamepass.
local function onSeatOccupantChanged()
if seat.Occupant then
local humanoid = seat.Occupant
local character = humanoid.Parent
local player = players:GetPlayerFromCharacter(character)
if player then
local success, result = pcall(function()
return marketplace:UserOwnsGamePassAsync(player.UserId, gamepassId)
end)
if success then
if result then
print(result)
return
end
else
warn(result)
end
success, result = pcall(function()
return marketplace:PromptGamePassPurchase(player, gamepassId)
end)
if success then
if result then
print(result)
end
else
warn(result)
end
local seatWeld = seat:FindFirstChild("SeatWeld")
if seatWeld then
seatWeld:Destroy()
end
end
end
end
seatEvent:Connect(onSeatOccupantChanged)
Here’s a script I recently wrote, it’ll prevent the player from staying seated in a vehicle’s seat if they don’t have the required gamepass. Additionally, a prompt to purchase the gamepass is displayed if the player doesn’t own the gamepass. The script is a server script which should be placed directly/immediately inside the seat instance of the vehicle.