Acess Datastore from another script

i have a donation board in my game and it is saving the date in the script below

local Datastore = game:GetService("DataStoreService"):GetDataStore("BoardData")
local Data = Datastore:GetAsync("Data")

when the player makes the donation, it probably saves on that date. Is it possible to access this date by another script to get the donation value of the player. I’m making an overhead and i want to show in the overhead the value that the player already donated.

You can use the two lines that you’ve defined above in multiple scripts with no problem at all. So, in another script that you want to access the data in, you can simply use the same code to get the saved data that you have used above.

1 Like

my script is like that:

local Datastore = game:GetService("DataStoreService"):GetDataStore("BoardData")
local Data = Datastore:GetAsync("Data")

local DonatorOverheadGui = ReplicatedStorage:WaitForChild("DonatorOverheadGui")

local Configuration = game.Workspace.Boards.R15Loader.Configuration
local DONATOR_ID = Configuration.userId


Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		local Head = Character:WaitForChild("Head")

                        if Player.UserId == DONATOR_ID.Value then
			
			local DonatorCloneGui = DonatorOverheadGui:Clone()
			DonatorCloneGui.Username.Text = Player.Name
			DonatorCloneGui.Name = "OverheadGui"
			DonatorCloneGui.Parent = Head
			DonatorCloneGui.Rank.Text = "💸|TOP DONATOR "..Data  <<--- HERE IS THE PROBLEM (WHAT SHOULD I PUT HERE TO SHOW THE VALUE

end
end)
end)

DonatorCloneGui.Rank.Text = ":money_with_wings:|TOP DONATOR "…Data <<— HERE IS THE PROBLEM (WHAT SHOULD I PUT HERE TO SHOW THE VALUE

How I take the value saved on the date and put it there. Because that way, it’s not working

Those are the DataStore information i have from the board:

local Datastore = game:GetService(“DataStoreService”):GetDataStore(“BoardData”)

local Data = Datastore:GetAsync(“Data”)

Datastore:SetAsync(“Data”,Data)

You’re not achieving the player’s data, only the key Data, which is global - not personal. You’re intended to save their own donation with their UserId, and retrieve it by utilising GlobalDataStore:GetAsync(plr.UserId). Here’s a sample:

local data --variable for the data if pcall is successful
local success, failed = pcall(function()
	data = dataStore:GetAsync(plr.UserId) or 0 --gets their data by plr.UserId, personal key. If they're a newcomer, their data with a value of 0 is made
end)
if failed then warn(failed); return end --if operation failed, it'll show a warning in the output

To save the data, utilise GlobalDataStore:UpdateAsync() for game.Players.PlayerRemoving event and game:BindToClose(). Read the articles to acknowledge how to use them.

If it’s too complicated, please wait till I’m done with writing a script.

1 Like

the donation board is not mine, it is free to use. And I don’t know how it saves the player donation data.

How’s the donation processed? Is it by a TextButton or anything?

this is the module
https://www.roblox.com/library/2925075326/Donate-Board-MainModule-V1

Okay, I presume I’ve misunderstood of what you were trying to achieve. It is possible to access the same DataStore through another script - simply copy the name and you’re set.

1 Like