Database editor support

Greetings. I am trying to find a way in order to change a certain user’s amount of points in my game, but cannot seem to figure it out. I was told that DataBase editor would supposedly be able to help. But I do not know anything about the DataBase editor, nor if I even need to use Database editor. Could someone tell me the name, the scope, and the key, or another way to change someone’s points?

This is for a hand to system., where staff get points when they handto.

    script.Parent.GiveItem.OnServerEvent:connect(function(plr, customer, order)
	pcall(function()
		if customer ~= nil and order ~= nil then
			local gui = script.Parent.reciever:Clone()
			gui.barista.Value = plr.Name
			order.Parent = gui
			gui.Frame.question.Text = "Would you like to recieve "..order.Name.." from " .. plr:GetRoleInGroup(script.Parent.GroupID.Value)..", "..plr.Name.."?"
			gui.Parent = customer.PlayerGui
		end
	end)
end)

local array = {}

function update(plr,points)
	for i=1,10 do
		if workspace.pointsboard.SurfaceGui.Frame["p"..i].plrname.Text == plr then
			if i~= 10 then
				for a=i+1, 10 do
					workspace.pointsboard.SurfaceGui.Frame["p"..a-1].plrname.Text = workspace.pointsboard.SurfaceGui.Frame["p"..a].plrname.Text
					workspace.pointsboard.SurfaceGui.Frame["p"..a-1].plrpoints.Text = workspace.pointsboard.SurfaceGui.Frame["p"..a].plrpoints.Text 
				end
			end
			workspace.pointsboard.SurfaceGui.Frame.p10.plrname.Text = ""
			workspace.pointsboard.SurfaceGui.Frame.p10.plrpoints.Text = "0"
			break
		end
	end
	
	--add the swap ranks bit here!
	local num = 0
	for i=1, 10 do
		if points > tonumber(workspace.pointsboard.SurfaceGui.Frame["p"..i].plrpoints.Text) then
			num = i
			break
		end
	end
	if num ~= 0 then
		for i=1,10-num do
			workspace.pointsboard.SurfaceGui.Frame["p"..(11-i)].plrpoints.Text = workspace.pointsboard.SurfaceGui.Frame["p"..(10-i)].plrpoints.Text
			workspace.pointsboard.SurfaceGui.Frame["p"..(11-i)].plrname.Text = workspace.pointsboard.SurfaceGui.Frame["p"..(10-i)].plrname.Text
		end
		workspace.pointsboard.SurfaceGui.Frame["p"..(num)].plrpoints.Text = points
		workspace.pointsboard.SurfaceGui.Frame["p"..(num)].plrname.Text = plr
	end
	return
	
end

game.Players.PlayerAdded:connect(function(player)
	--Stuff that defo works--
	local leaderstats = Instance.new("Model", player)
	leaderstats.Name = "leaderstats"

	local rank = Instance.new("StringValue", leaderstats) 
	rank.Name = "Rank" 
	rank.Value = player:GetRoleInGroup(script.Parent.GroupID.Value)
	
	if player:GetRankInGroup(script.Parent.GroupID.Value) >= script.Parent.RankID.Value or player.Name == "Wizzy011" or player.Name == "Player1" then
		local points = Instance.new("IntValue", leaderstats)
		points.Name = "Points"
		points.Value = game:GetService("DataStoreService"):GetDataStore("Points"):GetAsync("user_" ..player.userId)
		array[player.Name] = points.Value
		update(player.Name, points.Value)
		
	else
		local points = Instance.new("StringValue", leaderstats)
		points.Name = "Points"
		points.Value = "N/A"
	end
	if player:GetRankInGroup(script.Parent.GroupID.Value) >= script.Parent.AdminRankID.Value or player.Name == "MysteriouslyMythical" then
		player.Chatted:connect(function(msg)
			if string.sub(msg, 0,10) == "addpoints " then
				local nameend = string.find(msg, " ",11)
				if nameend ~= nil then
					local name = string.sub(msg, 11, nameend-1)
					local client = nil
					local count = 0
					for _,v in pairs(game.Players:GetPlayers()) do
						if string.lower(name) == string.lower(string.sub(v.Name,0,string.len(name))) then
							client = v.Name
							count = count+1
						end
					end
					if count == 1 then
						local points = string.sub(msg, nameend)
						if tonumber(points) ~= nil then
							if array[client] ~= nil then
								array[client] = array[client] + points
								pcall(function()
									game.Players[client].leaderstats.Points.Value = array[client]
								end)
								update(client, array[client])
							end
						end
					end
				end
			elseif string.sub(msg, 0,13) == "revokepoints " then
				local nameend = string.find(msg, " ",14)
				if nameend ~= nil then
					local name = string.sub(msg, 14, nameend-1)
					local client = nil
					local count = 0
					for _,v in pairs(game.Players:GetPlayers()) do
						if string.lower(name) == string.lower(string.sub(v.Name,0,string.len(name))) then
							client = v.Name
							count = count+1
						end
					end
					if count == 1 then
						local points = string.sub(msg, nameend)
						if tonumber(points) ~= nil then
							if array[client] ~= nil then 
								array[client] = array[client] - points
								pcall(function()
									game.Players[client].leaderstats.Points.Value = array[client]
								end)
								update(client, array[client])
							end
						end
					end
				end
			end
		end)
	end
end)

script.Parent.AddPoint.OnServerEvent:connect(function(cus,p)
	plr = game.Players:FindFirstChild(p)
	if plr ~= nil then
		plr.leaderstats.Points.Value = plr.leaderstats.Points.Value +1
		array[plr.Name] = plr.leaderstats.Points.Value	
		update(p, array[plr.Name])	
	end
end)

script.Parent.RevokePoint.OnServerEvent:connect(function(cus,p)
	plr = game.Players:FindFirstChild(p)
	if plr ~= nil then                 
		plr.leaderstats.Points.Value = plr.leaderstats.Points.Value -1
		--------
		array[plr.Name] = plr.leaderstats.Points.Value	
		update(p, array[plr.Name])	
	end
end)

game.Players.PlayerRemoving:connect(function(player)
	if array[player.Name] ~= nil then
		game:GetService("DataStoreService"):GetDataStore("Points"):UpdateAsync("user_"..player.userId, function(oldValue)
			local newValue = array[player.Name]
			local val = newValue
			return newValue
		end)
		wait()
		array[player.Name] = nil
		update(player.Name, -1000)
	end
end)

Look into using DataStore2, it’s really good for this case, since you can update it as many times as you want without throttling, it saves the data once player leaves game automatically, it’s good for data loss prevention as well.

Is it easier to use? (30 charters)

Yeah, for example

local DATASTORE_KEY = “Development1” – You can change the key to whatever
local DataStore2 = require(script.Parent:WaitForChild(“DataStore2”))
DataStore2.Combine(DATASTORE_KEY, “PlayerData”)
– So this sets up DataStore2, once you do this then you’re ready for use.

In Order to save data, heres a sample code to get you started:

local DataToSave = {cash = PlayerCashValue, RoleplayName = PlayerRoleplayName}
DataStore2(“PlayerData”, self._obj):Set(DataToSave )
– you can use the code above everytime something changes, since it doesnt automatically datastores it, put holds a copy of the data and then datastores it once player leaves or server ended to prevent data loss.

And if you want to retrieve the data, you just do the following:

local DataTemplate = {cash = 100, RoleplayName = “None”} – Default values for when user joins without anything saved.
local data = DataStore2(“PlayerData”, player):Get(DATA_TEMPLATE);
local LoadedCash = data.cash
local LoadedRoleplayName = data.RoleplayName

And that’s about it.

But for the code above what do I do, since it is already made and I don’t feel like rescripting that right now.

On playerRemoving try using the following,

local success, e = pcall(function()
game:GetService(“DataStoreService”):GetDataStore(“Points”):SetAsync(“user_”…player.userId, array[player.Name])
end)
if not success then warn(“Error saving data”) end

And remove your UpdateAsync function for updating the value.

I am just trying to give a player more points? Do I do this in F9 server?

Oh, then you can do

local PlayerName = “SomePlayerName”
local PointsToGive = 5
local stats = game.Players:FindFirstChild(PlayerName):FindFirstChild(“leaderstats”):FindFirstChild(“Points”)
if stats then stats.Value = stats.Value + PointsToGive end

Sorry I misinterpreted your question, you can run the following code on command console.

1 Like

Testing it on myself first. Here is the error code.

Where you see the quotation marks, " just replace them with the one on your keyboard, because for some reason when you copy the code from here, it uses different unicode

Nope, still not working.

you put this

stats.Value + PointsToGive

Instead, put this

stats.Value = stats.Value + PointsToGive

No error, but points did not go up.

( PS I DID PUT END AND PointsToGive. It just got cutoff.)

you wrote “if staats then” instead of “if stats then”

1 Like

Yep, noticed that just now. Mac got recalled due to this error where it double types. :roll_eyes:

1 Like

were you able to fix the issue?

Thank you so much! It worked. <3

1 Like

hey dude, anyway to make the points save? Because as soon as the user leaves, they reset.

I suppose I put that in the script and not the console, and this will make it save?

1 Like