I have been trying to implement the ProfileService Data Store and i am trying to store a string value but it always errors for some reason saying that the argument is nil. If i make it an int value it works fine somehow. Here is the code
local Players = game:GetService("Players")
local cachedProfiles = {}
local ProfileService = require(script.ProfileService)
local saveStructure = {
--Data
Cash = 0;
CurrentSkin = "";
Exp = 0;
}
local PlayerProfileStore = ProfileService.GetProfileStore("PlayerData",saveStructure)
local function PlayerDataLoaded(player)
local profile = cachedProfiles[player]
local leaderstats = Instance.new("Folder")
leaderstats.Name = "PlayerData"
leaderstats.Parent = player
local Skins = Instance.new("Folder")
Skins.Name = "Skins"
Skins.Parent = leaderstats
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Value = profile.Data.Cash
Cash.Parent = leaderstats
local Exp = Instance.new("IntValue")
Exp.Name = "Exp"
Exp.Parent = leaderstats
Exp.Value = profile.Data.Exp
local CurrentSkin = Instance.new("StringValue")
CurrentSkin.Name = "CurrentSkin"
CurrentSkin.Parent = leaderstats
CurrentSkin.Value = profile.Data.CurrentSkin --Errors here saying "invalid argument #3 (string expected, got nil)"
spawn(function()
while true do
local profile = cachedProfiles[player]
if profile ~= nil then
Cash.Value = profile.Data.Cash
Exp.Value = profile.Data.Exp
CurrentSkin.Value = profile.Data.CurrentSkin
else
break
end
wait(0.1)
end
end)
print(player.Name .. "'s data is loaded")
end
local function PlayerAdded(player)
local profile = PlayerProfileStore:LoadProfileAsync("Player_" .. player.UserId, "ForceLoad")
if profile ~= nil then
profile:ListenToRelease(function()
cachedProfiles[player] = nil
player:Kick("Your profile has been loaded remotely. Please rejoin.")
end)
if player:IsDescendantOf(Players) then
cachedProfiles[player] = profile
PlayerDataLoaded(player)
else
profile:Release()
end
else
player:Kick("Unable to load saved data. Please rejoin.")
end
end
for _, player in ipairs(Players:GetPlayers()) do
spawn(function()
PlayerAdded(player)
end)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(player)
local profile = cachedProfiles[player]
if profile ~= nil then
profile:Release()
end
end)
return cachedProfiles
I have tried setting in the CurrentSkins other strings and it just always does same error. If i make it an Int value and put a value it works fine but i want to store a string in there. If i can provide anything else let me know