Buy Morphs with Developer Product

Hi! so i have morphs i wanna sell by players standing on a part and it prompts them, so i currently have a working morph script and prompt except, when a player stands on the part they turn into the morph even without purchasing the product first. How would i fix that? I want it so that if they stand on it, it prompts them and if the buy, and then stand on it again it will morph them. thank you!

the script:

script.Parent.Touched:Connect(function(touc)
	local player = game.Players:FindFirstChild(touc.Parent.Name)
	if player then
		game:GetService("MarketplaceService"):PromptProductPurchase(player, 1234245814)
	end
end)


local pad = script.Parent
local characterName = "dolo"
local character = pad.Parent:WaitForChild(characterName)

local debounce = true
pad.Touched:Connect(function(obj)
	local plr = game.Players:GetPlayerFromCharacter(obj.Parent)
	if plr and debounce == true then
		debounce = false

		pad.BrickColor = BrickColor.new("Electric blue")

		local charClone = character:Clone()
		charClone.Name = plr.Name
		plr.Character = charClone

		local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChild("Torso")
		local plrRoot = obj.Parent:FindFirstChild("HumanoidRootPart") or obj.Parent:FindFirstChild("Torso")

		if rootPart and plrRoot then
			rootPart.CFrame = plrRoot.CFrame
		end

		charClone.Parent = workspace

		wait(.5)

		pad.BrickColor = BrickColor.new("Lime green")
		debounce = true
	end
end)

It’s happening because you are not checking if the purchase was successful and just morphing no matter what in you touched event

1 Like
script.Parent.Touched:Connect(function(touc)
	local player = game.Players:FindFirstChild(touc.Parent.Name)
	if player then
		if not game:GetService("MarketplaceService"):PlayerOwnsAsset(plr, 1234245814) then
			game:GetService("MarketplaceService"):PromptProductPurchase(player, 1234245814)
		end
	end
end)


local pad = script.Parent
local characterName = "dolo"
local character = pad.Parent:WaitForChild(characterName)

local debounce = true
pad.Touched:Connect(function(obj)
	local plr = game.Players:GetPlayerFromCharacter(obj.Parent)
	if plr and debounce == true then
		if not game:GetService("MarketplaceService"):PlayerOwnsAsset(plr, 1234245814) then
			return
		end
		debounce = false

		pad.BrickColor = BrickColor.new("Electric blue")

		local charClone = character:Clone()
		charClone.Name = plr.Name
		plr.Character = charClone

		local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChild("Torso")
		local plrRoot = obj.Parent:FindFirstChild("HumanoidRootPart") or obj.Parent:FindFirstChild("Torso")

		if rootPart and plrRoot then
			rootPart.CFrame = plrRoot.CFrame
		end

		charClone.Parent = workspace

		wait(.5)

		pad.BrickColor = BrickColor.new("Lime green")
		debounce = true
	end
end)

i updated it, tho now it wont morph

local Marketplace = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Part = script.Parent
local Model = Part.Parent
local Rig = Model:WaitForChild("dolo")

local Debounce = false

Part.Touched:Connect(function(Hit)
	if Debounce then
		return
	end
	local Player = Players:GetPlayerFromCharacter(Hit.Parent)
	if Player then
		Debounce = true
		Part.BrickColor = BrickColor.new("Electric blue")
		Marketplace:PromptProductPurchase(Player, 1234245814)
		task.wait(2)
		Debounce = false
		Part.BrickColor = BrickColor.new("Lime green")
	end
end)

local function ProcessReceipt(ReceiptInfo)
	local Player = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
	if Player then
		if ReceiptInfo.ProductId == 1234245814 then
			local Character = Player.Character
			local HRP = Character.HumanoidRootPart
			local RigClone = Rig:Clone()
			RigClone.Name = Player.Name
			Character = RigClone
			local Root = RigClone.HumanoidRootPart
			Root.CFrame = HRP.CFrame
			RigClone.Parent = workspace
		end
	end
end

Marketplace.ProcessReceipt = ProcessReceipt

https://developer.roblox.com/en-us/api-reference/callback/MarketplaceService/ProcessReceipt

Because you’ve used a Developer Product instead of a Gamepass you may wish store product purchases within a DataStore as there isn’t an available Roblox API which allows for you to check whether or not a user owns a product.