repStorage == game:GetService("ReplicatedStorage")
local remote = game.ReplicatedStorage.RemoteEvent
local DSService = game:GetService("DataStoreService"):GetDataStore("CreditStorage")
game.Players.PlayerAdded:connect(function(plr)
local uniquekey = "id-".. plr.userId
local leaderstats = Instance.new("IntValue",plr)
local savevalue = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
savevalue.Parent = leaderstats
savevalue.Name = "Credits"
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved [1]
else
local NumbersForSaving = {savevalue.Value}
DSService:SetAsync(uniquekey,NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = "id-"..plr.userId
local Savetable = {plr.leaderstats.Credits.Value}
DSService:SetAsync(uniquekey,Savetable)
remote.OnServerEvent(function(creditReduction)
--What would I put here to reduce the credit amount?
end)
end)
Just having some problems. Not sure what I would put for the event. Help? My local script is in the button, and they will be talking to each other. I am trying to get the data storage to update when the button is pressed.

5 comments
PlayerRemoving?
When a player is removed? That part works fine
plr.leaderstats.Credits.Value = plr.leaderstats.Credits.Value - creditReduction
Thanks! I'll test it our later
Sorry, you broke this rule: Attempts should be your own work. Don't take a free model and expect us to fix it.^ This is alvinbloxx's code.