local Data = game:GetService("DataStoreService"):GetDataStore("randomthingdatalolxd")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local money = Instance.new("NumberValue",leaderstats)
money.Name = "money"
money.Value = 0
local DataLoad = Data:GetAsync(tostring(player.UserId))
local Response, Success = pcall(function()
return DataLoad
end)
if Success then
money.Value = DataLoad[1]
print("Successively Loaded leaderstats!")
elseif not Success then
error("Failed to Load leaderstats.")
end
task.wait(0.4)
money.Value += 100
while task.wait(0.36) do
money.Value += 100
end
end)
game.Players.PlayerRemoving:Connect(function(player)
Data:SetAsync(tostring(player.UserId),{
player.leaderstats.money.Value
})
end)
Edit: Edited the Script: Added a Print Statement Of the Line 19.
local ds = game:GetService("DataStoreService")
create = function(classname, properties)
local i = Instance.new(classname)
for _,v in pairs(properties) do
i[_] = v
end
return i
end
local remote = create("RemoteEvent", {Name = "test", Parent = game.ReplicatedStorage})
remote.OnServerEvent:connect(function(self, val)
self.leaderstats.Money.Value = val
end)
game.Players.PlayerAdded:Connect(function(player)
local stats = create("Configuraion", {Parent = player, Name = "leaderstats"})
local Money = create("IntValue", {Parent = stats, Value = ds:GetDataStore("Money"):GetAsync(player.UserId) or 0, Name = "Money"})
Money.Changed:Connect(function(v)
ds:GetDataStore("Money"):SetAsync(player.UserId, v)
end)
end)
On client, wait like 2 secods and then on the command bar run this command: game.ReplicatedStorage.test:FireServer(90)
After that is ran, wait another second and try rejoining. It actually works for me, so if this errors I don’t know what to do. No need to set the scripts seperate.
But after you’re done testing, delete those lines:
local remote = create("RemoteEvent", {Name = "test", Parent = game.ReplicatedStorage})
remote.OnServerEvent:connect(function(self, val)
self.leaderstats.Money.Value = val
end)
local Data = game:GetService("DataStoreService"):GetDataStore("randomthingdatalolxd")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local money = Instance.new("NumberValue",leaderstats)
money.Name = "money"
money.Value = 0
local DataLoad = Data:GetAsync(tostring(player.UserId))
local Response, Success = pcall(function()
return DataLoad
end)
if Success then
money.Value = DataLoad[1]
print("Successively Loaded leaderstats!")
elseif not Success then
error("Failed to Load leaderstats.")
end
task.wait(0.4)
money.Value += 100
while task.wait(0.36) do
money.Value += 100
end
end)
game.Players.PlayerRemoving:Connect(function(player)
Data:SetAsync(tostring(player.UserId),{
player.leaderstats.money.Value
})
end)
local Data = game:GetService("DataStoreService"):GetDataStore("randomthingdatalolxd")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local money = Instance.new("NumberValue",leaderstats)
money.Name = "money"
money.Value = 0
local DataLoad = Data:GetAsync(tostring(player.UserId))
local Response, Success = pcall(function()
return DataLoad
end)
if Success then
money.Value = DataLoad[1]
print("Successively Loaded leaderstats!")
elseif not Success then
error("Failed to Load leaderstats.")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
Data:SetAsync(tostring(player.UserId),{
player.leaderstats.money.Value
})
end)
Add a part in workspace, add a ClickDetector inside of the Part on it and copy this script on it but Outside Of The ClickDetector: