Hi. I recently made a datastore system for a leaderstat. However it does not work as when I type the leaderstat in the script it breaks, as the leaderstat’s name is 2 words with a space. Is there a way I can write it in a script while still having the leaderboard show as 2 words?
A quick example:
Imagine I have a leaderstat called Crystal Shards. I want the leaderboard at the top to say Crystal Shards. The intValue is therefore named Crystal Shards. However when I write a script like so;
X = game.Players.RealPlayerName.leaderstats.Crystal Shards.Value
It fails as it cannot find leaderstats.Crystal, and sets the value to nil
local dataStoreService = game:GetService("DataStoreService")
local deathsDatastore = dataStoreService:GetDataStore("deathsDatastore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local deaths = Instance.new("IntValue")
deaths.Name = "skill issues"
deaths.Parent = leaderstats
player.CharacterAdded:Connect(function()
repeat wait() until player.Character ~= nil
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
deaths.Value += 1
end)
end)
local data
local success, errormessage = pcall(function()
data = deathsDatastore:GetAsync(player.UserId.."-deaths")
end)
if success then
deaths.Value = data
print("Player deaths datastore successfully retrieved")
else
print("Player deaths datastore retrieval failed")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
deathsDatastore:SetAsync(player.UserId.."-deaths",player.leaderstats["skill issues"].Value)
end)
if success == true then
print("Player deaths leaderstat saving successful")
else
print("Player deaths leaderstat saving failed")
warn(errormessage)
end
end)
The console says that the datastore was successfully retrieved, but the leaderstat stays at 0. Can’t see the aftereffects of leaving because then the console gets deleted