Help Needed With Datastores - Pretty Urgent

Not boring you with anything heres the code, its to save the discord UserId of the player. it’s for my money logging system.

-- Variables --
local DS = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local CoinsDataStore = DS:GetDataStore("CoinsDS")
local SM = require(script.DiscordStats)

Players.PlayerAdded:Connect(function(Player)
	local key = -- not telling
	print("Data Key of " .. Player.Name .. ":" .. key)
	local Coins = SM.AddPlayerStats(Player)
	
	local success, CoinData = pcall(function()
		return CoinsDataStore:GetAsync(key)
	end)
	Coins.Value = (type(CoinData) == "number" and CoinData) or 0
	
end)

Players.PlayerRemoving:Connect(function(Player)
	local key = --not telling
	local DcData = Player.Discord
	local Coins = DcData.UUID.Value

	CoinsDataStore:UpdateAsync(key, function(oldData)
		return Coins
	end)
end)

If anyone could help me i would love it!

I even tried debugging it that didnt work, also yes, the game does have access to API services.

This should work outside Studio. If you want it to work in Studio as well, add game:BindToClose() to hold the server open to save data (this is because the server shuts down too fast for data to save):

game:BindToClose(function()
task.wait(1) -- keeps the server open for 1 second
end)

ur a real one man, i am also going to make a connect script for this that’s on the server but thats easy

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.