I have a datastore where it's supposed to save a StringValue inside the player named "CurrentPet". The problem is, it's giving the error "ServerScriptService.Leaderboard:11: bad argument #3 to 'Value' (string expected, got nil)" and I don't know why. Any help is appreciated, thanks!
local dss = game:GetService("DataStoreService"):GetDataStore("PetData")
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local currentpet = Instance.new("StringValue", player)
currentpet.Name = "CurrentPet"
local stats = dss:GetAsync(player.UserId)
if stats then
currentpet.Value = stats[1]
else
local savestat = currentpet.Value
dss:SetAsync(player.UserId, savestat)
end
end)
end)
game:GetService("Players").PlayerRemoving:Connect(function(player)
local savestat = player.CurrentPet.Value
dss:SetAsync(player.UserId, savestat)
end)
