Fixing a gamepass-only boat script

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.

The actual script works, this is probably just a logic error - and maybe the BoatSeat variable is referenced in the wrong area.

Try to just do like script.Parent.[whatever the script is called].Disabled = true for the boatseat.

Same thing happens either way, unfortunately

It’s referenced correctly, the script is directly inside the VehicleSeat

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

It’s not in workspace, it’s in replicated storage where the boat model is stored.

how are you sitting in the boat if its in replicatedstorage

It’s cloned, then put into workspace without those scripts

how is the boat gonna be disabled if it doesnt even have a script to disable it?

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)

Use this as a ServerScript:

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! :slightly_smiling_face:

I got it working; but thanks a bunch for your help anyways! :two_hearts:

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.