Hi, I working on a game with points and prestiges. Everything working fine except the prestige reset when the player rejoin.
Explication :
When the player join to prestige you need 10 points, after 20 points, and then 30 points (+10 every prestige so right now he is at 3 prestiges) BUT when he leave and rejoin he keep his 3 prestiges but restart with 10 points, 20 points, 30 points to prestige 6 . So he paying like low prestige but he is high prestige.
If someone can tell me what to change in my current script to prevent that ?
The script :
local replicatedStorage = game:GetService("ReplicatedStorage")
local buttonEvent = replicatedStorage:WaitForChild("PrestigeEvent")
local debounce = true
local pointsRequired = 10
local function buttonPressed(plr)
local pStats = plr:WaitForChild("leaderstats")
local pGui = plr:WaitForChild("PlayerGui")
local pPrestigeButton = pGui:WaitForChild("Buttons"):FindFirstChild("Prestige")
local pPoints = pStats:FindFirstChild("Points")
local pPrestige = pStats:FindFirstChild("Prestige")
if debounce and pPoints.Value >= pointsRequired then
debounce = false
pPrestige.Value = pPrestige.Value +1
pPoints.Value = 0
pointsRequired = pointsRequired + 10
pPrestigeButton.Text = "Prestige successfull"
wait(2)
pPrestigeButton.Text = "Prestige"
else
debounce = false
pPrestigeButton.Text = "Points required to prestige: "..tostring(pointsRequired)
wait(2)
pPrestigeButton.Text = "Prestige"
end
wait(0.5)
debounce = true
end
buttonEvent.OnServerEvent:Connect(buttonPressed)
local DS = game:GetService("DataStoreService"):GetDataStore("WaitingSimDatastore") --DON'T CHANGE "WaitingSimDatastore" OR ELSE IT WILL RESET DATA!
game.Players.PlayerAdded:Connect(function(plr)
--=Set up variables/values=--
local ls = Instance.new("Folder",plr)
local points = Instance.new("IntValue",ls)
local mult = Instance.new("IntValue",plr)
local prestige = Instance.new("IntValue",ls)
--=Define variables=--
ls.Name = "leaderstats"
points.Name = "Points"
points.Value = 0
mult.Name = "Multiplier"
prestige.Name = "Prestige"
--=Datastore things=--
--=/Points=--
local id = points.Name.."-"..plr.UserId --Datastore id, should look like Points-92345351 or something idk
local data = nil
pcall (function() --Prevents script from commiting die
data = DS:GetAsync(id) --Get data from player owo
end)
if data ~= nil then
points.Value = data
print("Data loaded for "..plr.Name)
else
--This is a new player (or something went wrong)
print("New Player")
points.Value = 0
end
--=/Multiplier=--
local multid = mult.Name.."-"..plr.UserId --Saving for the multiplier
local multdata = nil
pcall (function()
multdata = DS:GetAsync(multid)
end)
if multdata ~= nil then
mult.Value = multdata
else
mult.Value = 1
end
--=/Rebirths=--
local prestigeid = prestige.Name.."-"..plr.UserId -- Saving for rebirths
local prestigedata = nil
pcall (function()
prestigedata = DS:GetAsync(prestigeid)
end)
if prestigedata ~= nil then
prestige.Value = prestigedata
else
prestige.Value = 1
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
--Save players data when they're leaving :3
local id = plr.leaderstats:WaitForChild("Points").Name.."-"..plr.UserId --Datastore id (again)
local multid = plr:WaitForChild("Multiplier").Name.."-"..plr.UserId --Datastore id (AGAIN)
local prestigeid = plr.leaderstats:WaitForChild("Prestige").Name.."-"..plr.UserId --AAAAAAAAAAAAAAAAAAAA
DS:SetAsync(prestigeid,plr.leaderstats.Prestige.value)
DS:SetAsync(multid,plr.Multiplier.Value)
DS:SetAsync(id,plr.leaderstats.Points.Value)
end)
--This will wait 5 seconds before letting the server close
game:BindToClose(function()
--Make sure if server shuts down for some reason that data saves
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick("Server shutting down. Data was saved")
end
end
wait(5)
end)
Sorry for the late reply, I was not notified of your response and I have not been on today. What was the red text above the second screenshot that you sent. You didn’t actually send the error, just the line.