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!
Make a rebirth system that doubles in cost of wins every time you have rebirthed. Example: You rebirthed at 5 wins your new cost will be 10 wins. -
What is the issue? Include screenshots / videos if possible!
The Rebirth system is not able to save when you rebirth and the cost would be the first cost you get before you rebirth. The cost is updated in a screen GUI.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried getting further support from other communities.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
ServerScript
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RebirthFunction = ReplicatedStorage:WaitForChild("Rebirth")
local RebirthFrame = game.StarterGui.ScreenGui.RebirthFrame.Cost
local MaxLevel = 5
local Abbreviations = {
"";
"K";
"M";
"B";
"T";
"Q";
"Qi";
"Sx";
"Sp";
"Oc";
"N";
"D";
"∞";
}
local function formatJumpHeight(jumpHeight)
for i = 1, #Abbreviations do
if jumpHeight < 10 ^ (i * 3) then
if Abbreviations[i] == "∞" then
return "∞"
else
return math.floor(jumpHeight / ((10 ^ ((i - 1) * 3)) / 100)) / 100 .. Abbreviations[i]
end
elseif tostring(jumpHeight) == "inf" then
return "∞"
end
end
end
-- Function to update player data in DataStore
local function updateDataStore(player)
local success, errorMessage = pcall(function()
local leaderstats = player:WaitForChild("leaderstats")
local jumpHeight = player.Character.Humanoid.JumpHeight
local winsValue = leaderstats:WaitForChild("Wins")
local rebirthsValue = leaderstats:WaitForChild("Rebirths")-- Assuming MaxLevel is a global variable
local rebirthframe = RebirthFrame
local data = {
JumpHeight = jumpHeight,
Wins = winsValue.Value,
Rebirths = rebirthsValue.Value,
Rebirth = tostring(rebirthframe)
}
myDataStore:SetAsync(player.UserId, data)
end)
if success then
print("Data is saved for " .. player.Name)
else
print("Error when saving data for " .. player.Name .. ": " .. errorMessage)
end
end
-- Function to load player data from DataStore
local function loadDataStore(player)
local success, errorMessage = pcall(function()
local data = myDataStore:GetAsync(player.UserId) or {}
local jumpHeight = data.JumpHeight
local wins = data.Wins
local rebirths = data.Rebirths
local rebirthcost = data.Rebirth
if jumpHeight ~= nil then
player.Character.Humanoid.JumpHeight = jumpHeight
end
if wins ~= nil then
local leaderstats = player:WaitForChild("leaderstats")
local winsValue = leaderstats:WaitForChild("Wins")
winsValue.Value = wins
end
if rebirths ~= nil then
local leaderstats = player:WaitForChild("leaderstats")
local rebirthsValue = leaderstats:WaitForChild("Rebirths")
rebirthsValue.Value = rebirths
end
if rebirthcost ~= nil then
rebirthcost = RebirthFrame
end
end)
if not success then
print("Error when loading data for " .. player.Name .. ": " .. errorMessage)
end
end
Local Script:
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RebirthFunction = ReplicatedStorage:WaitForChild("Rebirth")
local visible = false
local MaxLevel = 5
local OpenrebirthFrame = script.Parent:WaitForChild("RebirthOpen")
local RebirthFrame = script.Parent:WaitForChild("RebirthFrame")
local RebirthButton = RebirthFrame:WaitForChild("Rebirthing")
local leaderstats = player:WaitForChild("leaderstats")
local Rebirths = leaderstats:WaitForChild("Rebirths")
OpenrebirthFrame.MouseButton1Up:Connect(function()
if not visible then
RebirthFrame.Visible = true
RebirthFrame:TweenSizeAndPosition(
UDim2.new(0.5, 0, 0.5, 0),
UDim2.new(0.5, 0, 0.5, 0),
Enum.EasingDirection.Out,
Enum.EasingStyle.Sine,
0.5,
false
)
wait(0.5)
visible = true
RebirthFrame.Exit.MouseButton1Click:Connect(function()
RebirthFrame:TweenSizeAndPosition(
UDim2.new(0.01, 0, 0.01, 0),
UDim2.new(0.5, 0, 1.5, 0),
Enum.EasingDirection.Out,
Enum.EasingStyle.Sine,
0.5,
false
)
wait(0.5)
visible = false
RebirthFrame.Visible = false
end)
end
local newMultiplier = Rebirths.Value + 2
RebirthFrame.Multiplier.Text = "Your new multiplier will be "..newMultiplier .. "x"
end)
RebirthButton.MouseButton1Up:Connect(function(player)
local Wins = leaderstats:WaitForChild("Wins")
print(Wins.Value)
print("Wins.Value:", Wins.Value)
print("MaxLevel:", MaxLevel)
if Wins.Value >= MaxLevel then
local didPlayerRebirth = RebirthFunction:InvokeServer()
didPlayerRebirth = true
print(didPlayerRebirth)
local newMultiplier = Rebirths.Value + 2
RebirthFrame.Multiplier.Text = "Your new multiplier will be "..newMultiplier .. "x"
MaxLevel = MaxLevel * 2
local newCost = MaxLevel
RebirthFrame.Cost.Text = "Cost: " .. newCost .. "Wins"
else
RebirthFrame.Cost.Text = "Not enough wins"
wait(3)
local newCost = MaxLevel
RebirthFrame.Cost.Text = "Cost: " .. newCost .. " Wins"
end
end)
The New multiplier variable that is in the GUI is able to save because it is connected with the Rebirths value that is saved already in the leader stats. However, the new cost variable is unable to save because it is not connected with anything that has been saved. I am not sure if this is important information but I am trying to give you the most information about my situation as possible.
Please do not ask people to write entire scripts or design entire systems for you.
If you can’t answer the three questions above, you should probably pick a different category.