You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve?
I want to create a system in my Roblox game where players can purchase a dev product that allows them to reroll their character’s height using BodyHeightScale. When purchased, The new height should be randomly selected within a specified range and saved to the player’s data. The player’s character should automatically respawn with the new height applied. -
What is the issue?
after purchasing the product, the player’s height is not changing, the data is not being saved, and the character is not respawning automatically. There are no errors in the output making it harder for me to understand the problem. - What solutions have you tried so far?
- Checking that the
humanoid.Health = 0line is included to kill the player’s character and trigger a respawn, but that didn’t even do anything because my character never died when purchasing the product
This is the code when its purchased:
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local heightStore = DataStoreService:GetDataStore("PlayerHeights")
local ProductId = 1809068110
local function setHeightAndRespawn(player)
-- height reroll
local newHeight = math.random(110, 150) / 100
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.BodyHeightScale.Value = newHeight
-- saving new height to datastore
pcall(function()
heightStore:SetAsync(tostring(player.UserId), newHeight)
end)
-- respawn
humanoid.Health = 0
end
-- product purchase handler
local function onProductPurchase(playerId, receiptInfo)
-- double checking if the receipt is valid and for the correct product
if receiptInfo and receiptInfo.ProductId == ProductId then
local player = Players:GetPlayerByUserId(playerId)
if player then
setHeightAndRespawn(player)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
else
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end
MarketplaceService.ProcessReceipt = onProductPurchase
I have no clue what could be missing or wrong with this script and also this is my first topic!
