Transferring a leaderboard stat to another

Hello and thank you for reading this.

Currently, right now I have a script that lets you convert the value of a leader stat “egg” into the value of a leader stat “child”. This is done through leaderboards and the code is working just fine. I have a “sell” part you have to touch that makes the leader stat value of “Egg” change over to “Children”, however, if the player has, for example, 2 eggs, and goes to touch the part to convert them, it only gives them +1 children and not +2. Basically, I want to make it so that however many eggs the player has, it’ll convert them into that many children. How can I do this?

Here’s the code that I have which is a script in the “sell” part (Any help would be greatly appreciated!):

local part = script.Parent

local function collect(otherpart)
local player = game.Players:FindFirstChild(otherpart.Parent.Name)
if player then
local playerEggs = player.leaderstats.Eggs.Value
if playerEggs > 0 then
player.leaderstats.Eggs.Value = 0
player.leaderstats.Children.Value = player.leaderstats.Children.Value + 1
end
end
end

part.Touched:Connect(collect)


This is because you’re only adding 1. You should be adding playerEggs instead

1 Like
if playerEggs > 0 then
    player.leaderstats.Children.Value += player.leaderstats.Children.Value + playerEggs
    player.leaderstats.Eggs.Value = 0
    
end
1 Like

Thank you so much this really helped! :slight_smile:

Thank you to you as well for writing the new portion of the script :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.