Script kills player car gamepass script

Hi so I made this script local GPID = script.Parent.Configuration.Gamepass.Value
local MarketplaceService = game:GetService(“MarketplaceService”)
local ProximityPromptService = game:GetService(“ProximityPromptService”)
local gui = script.NoGamePass

script.Parent.ChildAdded:connect(function(child)
if child.Name == “SeatWeld” then
local Player = game.Players:GetPlayerFromCharacter(script.Parent.SeatWeld.Part1.Parent)
if MarketplaceService:UserOwnsGamePassAsync(Player.userId, GPID) then
end
else
ProximityPromptService.PromptTriggered:Connect(function(prompt, player)
if prompt.Name == “EndorsedVehicleProximityPromptV1” then
player.Character.Humanoid.Health = 0
player:LoadCharacter()
local a = gui:Clone()
a.Parent = player.PlayerGui
a.Enabled = true
wait(5)
a:Destroy()
end
end)
end
end) that is supposed to kill the player if they enter the car snd they dont own the gamepass but when i purchase the gamepass in test purchase in roblox studio it doesnt work it still kills me.

2 Likes

Maybe its because you are using MarketPlaceService instead of BadgeService… :thinking: :thinking: :thinking:

2 Likes

can you resend the code correctly formatted by selecting the code and pressing the </> button before sending so it is easier to read

1 Like
type or paste code here
```local GPID = script.Parent.Configuration.Gamepass.Value
local MarketplaceService = game:GetService("MarketplaceService")
local ProximityPromptService = game:GetService("ProximityPromptService")
local gui = script.NoGamePass

script.Parent.ChildAdded:connect(function(child)
    if child.Name == "SeatWeld" then
        local Player = game.Players:GetPlayerFromCharacter(script.Parent.SeatWeld.Part1.Parent)
		if MarketplaceService:UserOwnsGamePassAsync(Player.userId, GPID) then
end
		else
			ProximityPromptService.PromptTriggered:Connect(function(prompt, player)
				if prompt.Name == "EndorsedVehicleProximityPromptV1" then
			player.Character.Humanoid.Health = 0
			player:LoadCharacter()  
			local a = gui:Clone()
			a.Parent = player.PlayerGui
			a.Enabled = true
			wait(5)
			a:Destroy()
			end
        end)
    end
end)

try this code or somethin ig

local GPID = script.Parent.Configuration.Gamepass.Value
local MarketplaceService = game:GetService("MarketplaceService")
local ProximityPromptService = game:GetService("ProximityPromptService")
local gui = script.NoGamePass

script.Parent.ChildAdded:Connect(function(child)
    if child.Name == "SeatWeld" then
        local Player = game.Players:GetPlayerFromCharacter(script.Parent.SeatWeld.Part1.Parent)
        if Player then
            MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GPID):andThen(function(ownsGamepass)
                if not ownsGamepass then
                    ProximityPromptService.PromptTriggered:Connect(function(prompt, player)
                        if prompt.Name == "EndorsedVehicleProximityPromptV1" then
                            player.Character.Humanoid.Health = 0
                            player:LoadCharacter()
                            local a = gui:Clone()
                            a.Parent = player.PlayerGui
                            a.Enabled = true
                            wait(5)
                            a:Destroy()
                        end
                    end)
                end
            end):catch(function(err)
                warn("Error checking gamepass ownership: " .. err)
            end)
        end
    end
end)