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 would like the Max Level of a rebirth system to save. The MaxLevel value is sent to the client script through a remote function and the max level doubles every time the player rebirths. -
What is the issue? Include screenshots / videos if possible!
The issue is that it will not save and there is nothing in the workspace its just a variable. The MaxLevel variable always resets to 5 when the player leaves. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried getting help 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!
Server Script:
local MaxLevel = 5
local function updateDataStore(player)
local success, errorMessage = pcall(function()
myDataStore:SetAsync(player.UserId .. "JumpHeight", player.Character.Humanoid.JumpHeight)
local leaderstats = player:WaitForChild("leaderstats")
local winsValue = leaderstats:WaitForChild("Wins")
myDataStore:SetAsync(player.UserId .. "Wins", winsValue.Value)
local RebirthsValue = leaderstats:WaitForChild("Rebirths")
myDataStore:SetAsync(player.UserId .. "Rebirths", RebirthsValue.Value)
myDataStore:SetAsync(player.UserId .. "MaxLevel", MaxLevel)
end)
if success then
print("Data is saved for " .. player.Name)
else
print("Error when saving data for " .. player.Name .. ": " .. errorMessage)
end
end
local function loadDataStore(player)
local success, errorMessage = pcall(function()
local jumpHeightData = myDataStore:GetAsync(player.UserId .. "JumpHeight")
local winsData = myDataStore:GetAsync(player.UserId .. "Wins")
local Rebirthdata = myDataStore:GetAsync(player.UserId .. "Rebirths")
local MaxLevelData = myDataStore:GetAsync(player.UserId .. "MaxLevel")
if jumpHeightData ~= nil then
player.Character.Humanoid.JumpHeight = jumpHeightData
end
if winsData ~= nil then
local leaderstats = player:WaitForChild("leaderstats")
local winsValue = leaderstats:WaitForChild("Wins")
winsValue.Value = winsData
end
if Rebirthdata ~= nil then
local leaderstats = player:WaitForChild("leaderstats")
local RebirthData = leaderstats:WaitForChild("Rebirths")
RebirthData.Value = Rebirthdata
end
if MaxLevelData ~= nil then
MaxLevel = MaxLevelData
end
end)
if not success then
print("Error when loading data for " .. player.Name .. ": " .. errorMessage)
end
end
RebirthFunction.OnServerInvoke = function(player)
if player.leaderstats.Wins.Value >= MaxLevel then
player.leaderstats.Rebirths.Value = player.leaderstats.Rebirths.Value + 1
player.leaderstats.Wins.Value = 0
player.Character.Humanoid.JumpHeight = 0
end
return false
end
Local Script:
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()
print("Boy")
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 * 2
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.