You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want it to when you buy the revival product, it will restore the player’s size the player got by eating the balls -
What is the issue? Include screenshots / videos if possible!
On my death GUI, when you hit the revival button in Purcass, the revival button it will respawn the player in restore the eatCount, but it’s not restoring the size of the player -
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
I try making an applyMorphScale function in my revival button server script
here my client script
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local respawnButton = script.Parent.MainFrame:WaitForChild("respawn")
local deathGui = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local reviveButton = deathGui.MainFrame:WaitForChild("revive")
local REVIVE_PRODUCT_ID = 3392989558
local respawnEvent = ReplicatedStorage:WaitForChild("RespawnEvent")
deathGui.Enabled = false
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
deathGui.Enabled = true
end)
end
if player.Character then
onCharacterAdded(player.Character)
end
player.CharacterAdded:Connect(onCharacterAdded)
respawnButton.MouseButton1Click:Connect(function()
deathGui.Enabled = false
respawnEvent:FireServer("respawn")
end)
reviveButton.MouseButton1Click:Connect(function()
MarketplaceService:PromptProductPurchase(player, REVIVE_PRODUCT_ID)
end)
Here is my server script
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local REVIVE_PRODUCT_ID = 3392989558
local lastEatCount = {}
local lastScale = {}
local function setupCharacter(player, character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
local eatCount = player:FindFirstChild("EatCount")
if eatCount then
lastEatCount[player.UserId] = eatCount.Value
end
lastScale[player.UserId] = character:GetScale()
end)
end
local function applyMorphScale(character, eatCount)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local scale = 1 + (eatCount * 0.05)
humanoid:ScaleTo(scale)
end
end
MarketplaceService.ProcessReceipt = function(receiptinfo)
if receiptinfo.ProductId == REVIVE_PRODUCT_ID then
local player = Players:GetPlayerByUserId(receiptinfo.PlayerId)
if player then
local savedEat = lastEatCount[player.UserId] or 0
local savedScale = lastScale[player.UserId] or 1
player:LoadCharacter()
local char = player.CharacterAdded:Wait()
task.wait(0.2)
local eatCount = player:FindFirstChild("EatCount")
if eatCount then
eatCount.Value = savedEat
applyMorphScale(char, savedEat)
end
setupCharacter(player, char)
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
Players.CharacterAutoLoads = false
local respawnEvent = ReplicatedStorage:WaitForChild("RespawnEvent")
respawnEvent.OnServerEvent:Connect(function(player, action)
if action == "respawn" then
player:LoadCharacter()
end
end)
Players.PlayerAdded:Connect(function(player)
player:LoadCharacter()
player.CharacterAdded:Connect(function(char)
setupCharacter(player, char)
end)
end)
hers my player script that controls the sizing in the eatCount value when eating the balls, in case it’s needed
local character = script.Parent
local humanoidRoot = character:WaitForChild("HumanoidRootPart")
local morphGui = character:WaitForChild("Union"):WaitForChild("BillboardGui")
local textLabel = morphGui:WaitForChild("size")
local usernameLabel = morphGui:WaitForChild("username")
local placeLabel = morphGui:WaitForChild("placemarks")
local humanoid = character:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
local eatSound = Instance.new("Sound")
eatSound.Name = "EatSound"
eatSound.SoundId = "rbxassetid://6823523283"
eatSound.Volume = 1
eatSound.Parent = humanoidRoot
local eatCount = player:FindFirstChild("EatCount")
if not eatCount then
eatCount = Instance.new("IntValue")
eatCount.Name = "EatCount"
eatCount.Value = 0
eatCount.Parent = player
end
local function updatePlacements()
local playersData = {}
for _, plr in ipairs(game.Players:GetPlayers()) do
if plr and plr:FindFirstChild("EatCount") then
table.insert(playersData, {
Player = plr,
Count = plr.EatCount.Value
})
end
end
table.sort(playersData, function(a, b)
return a.Count > b.Count
end)
for i, data in ipairs(playersData) do
if data.Player.Character then
local char = data.Player.Character
local union = char:FindFirstChild("Union")
if union and union:FindFirstChild("BillboardGui") then
local billboard = union:FindFirstChild("BillboardGui")
local placeText = billboard:FindFirstChild("placemarks")
if placeText then
placeText.Text = tostring(i)
end
end
end
end
end
local function updateGui()
textLabel.Text = tostring(eatCount.Value)
if usernameLabel and player then
usernameLabel.Text = player.DisplayName
end
updatePlacements()
end
updateGui()
local function growMorph()
local growAmount = 0.05
local currentScale = character:GetScale()
local newScale = currentScale * (1 + growAmount)
local growDifference = (newScale - currentScale)
character:ScaleTo(newScale)
humanoidRoot.CFrame += Vector3.new(0, growDifference * 2, 0)
end
local function regenerateBall(originalBall)
task.delay(3, function()
if workspace:FindFirstChild("balls") then
local newBall = Instance.new("Part")
newBall.Name = originalBall.Name
newBall.Shape = Enum.PartType.Ball
newBall.Size = originalBall.Size
newBall.Position = originalBall.Position
newBall.Color = originalBall.Color
newBall.Anchored = originalBall.Anchored
newBall.CanCollide = originalBall.CanCollide
newBall.Parent = workspace:WaitForChild("balls")
local touched = false
newBall.Touched:Connect(function(hit)
if not touched and hit.Parent == character then
touched = true
eatCount.Value += 1
updateGui()
growMorph()
if eatSound then
eatSound:Play()
end
newBall:Destroy()
regenerateBall(originalBall)
end
end)
end
end)
end
for _, ball in ipairs(workspace:WaitForChild("balls"):GetChildren()) do
if ball:IsA("Part") then
local touched = false
ball.Touched:Connect(function(hit)
if not touched and hit.Parent == character then
touched = true
eatCount.Value += 1
updateGui()
growMorph()
if eatSound then
eatSound:Play()
end
ball:Destroy()
regenerateBall(ball)
end
end)
end
end
humanoidRoot.Touched:Connect(function(hit)
local otherChar = hit.Parent
if otherChar and otherChar ~= character and otherChar:FindFirstChild("Humanoid") then
local otherPlayer = game.Players:GetPlayerFromCharacter(otherChar)
if otherPlayer and otherPlayer:FindFirstChild("EatCount") then
local otherCount = otherPlayer.EatCount.Value
if eatCount.Value > otherCount then
eatCount.Value += otherCount
updateGui()
growMorph()
if eatSound then eatSound:Play() end
otherChar:FindFirstChild("Humanoid"):TakeDamage(1000)
end
end
end
end)
eatCount.Changed:Connect(updatePlacements)