Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I remove something of of a Database?

Its me again. After my brother and I started playing the game. I noticed that my economy was getting inflated. How do I reset the database to remove my code?

I used the database by jcs801

-- Read the description of the model for details, it pretty much says to just put it in.


function onPlayerEntered(player)
wait()-- Change to wait for player longer.
player:WaitForDataReady()
repeat wait() until player:FindFirstChild("leaderstats")
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(score[i].Name)
wait()
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end

function onPlayerLeaving(player)
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
player:SaveNumber(score[i].Name,score[i].Value)
end
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)

2 comments

0

I've given you an answer but take note it isn't called Database XD, It's referred to as "Data Persistence"

0

I had to update my code with a fix, you may want to use the updated post.

1 answer

✓ Accepted answer

What I did was simply renamed your databases by adding on to it with another key.

function onPlayerEntered(player)
wait()-- Change to wait for player longer.
player:WaitForDataReady()
repeat wait() until player:FindFirstChild("leaderstats")
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(score[i].Name.."DP")
wait()
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end

function onPlayerLeaving(player)
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
player:SaveNumber(score[i].Name.."DP",score[i].Value)
end
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)

5 comments

0

Now if your default database was "Item" it now saves under the persistence of "ItemDP"

0

Shouldn't the .."DP" be on the Name and not the Value on line 23?

0

Thanks, I overlooked that :-)

0

@Null, he's saving it as a data persistence. If he were to do what you're thinking of, he'd have to rename everything that he has saving. It's easier to save it with an extra string attatched.

0

You're correct. I've fixed the issue.

This discussion is preserved as it was. New answers, comments, and votes are closed.