Hello there everyone! So my issue that I am currently having is that the leaderstat is not functioning and when I review the script in ServerScriptService, nothing seems to be wrong. So far, I’ve tried to use different scripts, but nothing seems to work. One thing that I do notice is that when I try making a currency leaderstat in a different game(in roblox studio), the leaderstat seems to work perfectly fine. Any suggestions or things I can do to resolve this issue?
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local SoulTokens = Instance.new("IntValue")
SoulTokens.Name = "SoulTokens" -- currency name
SoulTokens.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId.."-SoulTokens")
end)
if success then
SoulTokens.Value = data
else
print("there was an error while getting your data ")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local succes, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-SoulTokens",player.leaderstats.SoulTokens.Value)
end)
if succes then
print("Data successfully saved!")
else
print("There was an error when saving data")
warn(errormessage)
end
end)