daulric
(Ulric)
November 1, 2021, 8:24pm
1
So i kinda stuck on this datastore script on leaderstats. Idk if yall could help me or something. This is my script
local DataSore = game:GetService("DataStoreService")
local ds = DataSore:GetDataStore("Points")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local points = Instance.new("IntValue")
points.Name = "Points"
points.Value = 0 or ds:SetAsync(points.Value)
points.Parent = leaderstats
player.CharacterAdded:Connect(function(Character)
Character.Humanoid.Died:Connect(function(Died)
local creator = Character.Humanoid:FindFirstChild("creator")
local leaderstats = creator.Value:FindFirstChild("leaderstats")
if creator ~= nil and creator.Value ~= nil then
leaderstats.Points.Value = leaderstats.Points.Value + 10
end
end)
end)
end)
So, that’s your DataStore script? Or that’s just your leaderstats and Kill for Cash Script?
7z99
(cody)
November 1, 2021, 8:34pm
3
I think it’s because of how you’re using or operators, essentially it should be value or fallback, not fallback or value because fallback will always be truthy. You’re also using :SetAsync instead of :GetAsync, you also don’t have a save function.
points.Value = ds:GetAsync(player.UserId) or 0
game:GetService('Players').PlayerRemoving:Connect(function(player)
ds:SetAsync(player.UserId, player:WaitForChild('leaderstats').Points.Value)
end)
I also highly suggest implementing pcalls as if your code errors, it will simply not load the data.
1 Like
daulric
(Ulric)
November 1, 2021, 10:18pm
4
thanks man. I really thought that datastore was for roblox studio but its really for Roblox Client/Player. thanks again!!
1 Like
7z99
(cody)
November 1, 2021, 10:19pm
5
Datastores should work in studio, just enable APIs under game settings.
daulric
(Ulric)
November 1, 2021, 10:48pm
6
i did that thank you man for the advise.
1 Like