My script doesn’t work in game but works perfect in studio, I have tried a ton of things like switching up vairables, etc.
local mps = game:GetService(‘MarketplaceService’)
local players = game:GetService(‘Players’)
local SoundService = game:GetService(‘SoundService’)
local LevelsFolder = workspace:WaitForChild(“Levels”)
local Products = {}
– Function to play sounds locally
local function playLocalSound(player, soundName)
if SoundService:FindFirstChild(soundName) then
local sound = SoundService[soundName]:Clone()
sound.Parent = player:FindFirstChild(“PlayerGui”) or player
sound:Play()
sound.Ended:Connect(function()
sound:Destroy()
end)
end
end
Products[2682199705] = function(player) – 1x skips
if player then
player.leaderstats.Skips.Value += 1
playLocalSound(player, “PurchaseSkip”)
return true
else
return false
end
end
Products[2682200237] = function(player) – 5x skips
if player then
player.leaderstats.Skips.Value += 5
playLocalSound(player, “PurchaseSkip”)
return true
else
return false
end
end
Products[2682200442] = function(player) – 10x skips
if player then
player.leaderstats.Skips.Value += 10
playLocalSound(player, “PurchaseSkip”)
return true
else
return false
end
end
Products[2669427924] = function(player) – revive
if player then
local lastTouchedPartName = player:GetAttribute(“LastTouchedPart”) – Get the name of the last touched part
if lastTouchedPartName then
local lastTouchedPart = LevelsFolder:FindFirstChild(lastTouchedPartName)
if lastTouchedPart then
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:FindFirstChild(“HumanoidRootPart”)
if humanoidRootPart then
humanoidRootPart.CFrame = lastTouchedPart.CFrame
playLocalSound(player, “PurchaseSkip”)
return true
end
end
end
end
return false
end
– Handle product purchase
mps.ProcessReceipt = function(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local handler = Products[receiptInfo.ProductId]
if handler then
local success = handler(player)
if success then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end
– Revive handling
players.PlayerAdded:Connect(function(player)
player:SetAttribute(“LastTouchedPart”, nil)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
mps:PromptProductPurchase(player, 2669427924)
end)
end)
end)
– Last touched positions
for _, part in ipairs(LevelsFolder:GetChildren()) do
part.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChild(“Humanoid”)
local player = players:GetPlayerFromCharacter(character)
if humanoid and player then
player:SetAttribute(“LastTouchedPart”, part.Name) – Store the name of the touched part
end
end)
end