DataStore2 Help

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I modified the base datastore script from DataStore2 examples, but it doesnt show your money amount after you die.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Ive made the module fire when they player is added and character added.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Players = game:GetService("Players")
local dataModule = require(script.CoinStoreFunctions)

Players.PlayerAdded:Connect(function(player)
	dataModule.setup(player)
end)

Players.PlayerAdded:Coonect(function(player)
	player.CharacterAdded:Connect(function(character)
		dataModule.setup(player)
	end)
end)

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Workspace = game:GetService("Workspace")
local DataStore2 = require(ServerScriptService.DataStore2)

-- Combine every key you use. This will eventually be the default, but for now read the "Gotchas" section to understand why we need this.
DataStore2.Combine("DATA", "points")


local functions = {}

function functions.setup(player)
	local pointsStore = DataStore2("points", player)

	local points = player.PlayerGui:WaitForChild("TextShower")
	points:WaitForChild("Template"):WaitForChild("TextLabel").Text = pointsStore:Get(50) -- The "0" means that by default, they'll have 0 points

	pointsStore:OnUpdate(function(newPoints)
		-- This function runs every time the value inside the data store changes.
		wait(1.5)
		points.Template.TextLabel.Text = newPoints
	end)
end

function functions.increment(player, amount)
	local pointsStore = DataStore2("points", player)
	pointsStore:Increment(amount) -- Give them 1 point
end

return functions

Disable the ScreenGui.ResetOnSpawn property, and then you do not have to set up every time the player respawns.

1 Like

Ill try that, Thank You. If it work ill mark as solution.