Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this dev product script not teleport the player after the player buys the product?

Asked by
Prioxis 673 Moderation Voter
9 years ago

I'm marking a obby to where you can teleport half way but my developer products screen gui it prompts the developer products to be bought but after the player buys the dev product nothing happens.... There's a function in the script that should teleport the player by using CFrame of the players Torso.. There's no errors in the dev console...

**Here's my script : **

--[[This script goes inside of a TextBox which should be inside of a ScreenGui]]
productId = 22158084 -- Replace 123123123 with the id of your developer product.
local Player = game.Players.LocalPlayer
script.Parent.MouseEnter:connect(function(Enter)
    script.Parent.Style = "RobloxButtonDefault"
    script.Parent.Size = UDim2.new(0, 215, 0, 55)
end)


script.Parent.MouseLeave:connect(function(Leave)
    script.Parent.Style = "RobloxButton"
    script.Parent.Size = UDim2.new(0, 200, 0, 50)
end)


local MarketplaceService = Game:GetService("MarketplaceService")
function UsernameFromID(ID)
    if type(ID) ~= "number" then
    return
    end
    local sets = game:service("InsertService"):GetUserSets(ID)
    for k, v in next, sets do
        if v.Name == "My Models" then
            return v.CreatorName
        end
    end
end
function giveRewards(player)
    print(Player.Name.. 'Bought Dev product')
Player.Character.Torso.CFrame = CFrame.new(-8, 34.5, -52)
    return Enum.ProductPurcaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = function(receiptInfo)
    giveRewards(UsernameFromID(receiptInfo.PlayerId))
end
script.Parent.MouseButton1Down:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(script.Parent.Parent.Parent.Parent, productId)
end)

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

The problem you have is that you're making functions for every bit of event that must happen in a Developer Product, but, one.. not Calling them, and two.. Not using them in the ProcessReceipt of MarketPlaceService.

So, to fix.. Negate the functions from your script, and put it all the ProcessReceipt functions tied to MarketPlaceService.

local productId = 22158084
local Player = game.Players.LocalPlayer
local MarketplaceService = Game:GetService("MarketplaceService")

script.Parent.MouseEnter:connect(function(Enter)
    script.Parent.Style = "RobloxButtonDefault"
    script.Parent.Size = UDim2.new(0, 215, 0, 55)
end)

script.Parent.MouseLeave:connect(function(Leave)
    script.Parent.Style = "RobloxButton"
    script.Parent.Size = UDim2.new(0, 200, 0, 50)
end)

function tele(plr)
    plr.Character.Torso.CFrame = CFrame.new(-8, 34.5, -52)
end

MarketPlaceService.ProcessReceipt = function(receiptInfo)
    for i,v in pairs(game.Players:GetPlayers()) do
        if v.userId == receiptInfo.PlayerId then
                print(Player.Name.. 'Bought Dev product')
            tele(v)
             return Enum.ProductPurcaseDecision.PurchaseGranted
        end
        MarketplaceService.ProcessReceipt = function(receiptInfo)
         giveRewards(UsernameFromID(receiptInfo.PlayerId))
    end
end

script.Parent.MouseButton1Down:connect(function()
    MarketPlaceService:PromptProductPurchase(Player, productId)
end)

I'm also not entirely sure what you were trying to accomplish with the user sets so I took that out of your script, if it's needed then PM me and i'll fix it.

Ad

Answer this question