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 the cost of my rebirth system to save so when they leave they are shown a new cost to save and not the first one. -
What is the issue? Include screenshots / videos if possible!
The issue is it won’t save. Here is the workspace:
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried searching for help from different communities. I did not need help from the Developer Hub.
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 RebirthFrame = game.StarterGui.ScreenGui.RebirthFrame.Cost
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 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()
RebirthFrame.Visible = not RebirthFrame.Visible
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)
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.