E Prompt Gamepass Spawner part

I’m making a car game, and I have tried some few ways but it’s not working for me.
so basically there is a part in workspace which allows me to spawn or you can say clone
the car from ReplicatedStorage.

so there is E prompt inside of that part which allows me to spawn the car and it works perfectly fine,
but I want to make a E prompt gamepass spawner I mean If they want to spawn that car they need
that gamepass to spawn it and if they have the gamepass then they can just directly spawn it without any gamepass owned or any pops up… Please help me with this script.

The script I’m using inside of that part:
local model = game.ReplicatedStorage.Car
local car = model.RacingCar:Clone()
local button = script.Parent
local sound = button.Sound

local regenerated = false
local ReloadTime = 10

local mps = game:GetService(“MarketplaceService”)

script.Parent.ProximityPrompt.Triggered:connect(function(plr)
if mps:UserOwnsGamePassAsync(plr, GAMEPASSID) then
if regenerated == false then

	regenerated = true
	button.BrickColor = BrickColor.new("Bright red")
	sound:Play()
	
	local newcar = car:Clone()
	newcar.Name = "RacingCar"
	newcar.Parent = workspace.SpawnedCar
	newcar:MakeJoints()
	
	wait(ReloadTime)

	regenerated = false
	button.BrickColor = BrickColor.new("Dark green")
	
	else

	return
		end
end

end)

I assume you got the gamepass owned and car spawning parts working…

local car = model.RacingCar:Clone()
local button = script.Parent
local sound = button.Sound

local regenerated = false
local ReloadTime = 10

local mps = game:GetService(“MarketplaceService”)

script.Parent.ProximityPrompt.Triggered:connect(function(plr)
if mps:UserOwnsGamePassAsync(plr, GAMEPASSID) then
   if regenerated == false then
     regenerated = true
	 button.BrickColor = BrickColor.new("Bright red")
	 sound:Play()
	
	 local newcar = car:Clone()
	 newcar.Name = "RacingCar"
	 newcar.Parent = workspace.SpawnedCar
	 newcar:MakeJoints()
	
	 wait(ReloadTime)

	 regenerated = false
	 button.BrickColor = BrickColor.new("Dark green")
	
   end
else 

mps:PromptGamePassPurchase(plr, GAMEPASSID)

end

end)

Explanation:
If the player does not own the gamepass, they will be prompted to buy the gamepass.

1 Like