I have saves but the bool values cause a warning “Unable to cast value to object”
Thanks for any help
Code-
local DataStoreService = game:GetService("DataStoreService")
local Store = DataStoreService:GetDataStore("Storage")
game.Players.PlayerRemoving:Connect(function(player)
local playerUserID = player.UserId
local Coins = player.Leaderstats.Coins.Value
--bools
local Future = player.Leaderstats.Swords.FutureSword.Value
local Light = player.Leaderstats.Swords.LightSword.Value
local Dark = player.Leaderstats.Swords.DarkSword.Value
local Demon = player.Leaderstats.Swords.DemonSword.Value
local Doom = player.Leaderstats.Swords.DoomSword.Value
--end bools
local setSuccess, errorMessage = pcall(function()
Store:SetAsync(playerUserID, Coins, Future, Light, Dark, Demon, Doom)
end)
if not setSuccess then
warn(errorMessage)
end
end)
game.Players.PlayerAdded:Connect(function(player)
local playerUserID = player.UserId
local getSuccess, Coins, Future, Light, Dark, Demon, Doom = pcall(function()
return Store:GetAsync(playerUserID)
end)
if getSuccess then
print(Coins)
print(Future)
print(Light)
print(Dark)
print(Demon)
print(Doom)
wait(1)
player.Leaderstats.Coins.Value = Coins
player.Leaderstats.Swords.FutureSword.Value = Future
player.Leaderstats.Swords.LightSword.Value = Light
player.Leaderstats.Swords.DarkSword.Value = Dark
player.Leaderstats.Swords.DemonSword.Value = Demon
player.Leaderstats.Swords.DoomSword.Value = Doom
end
end)
Well GetAsync would be returning a table so you’d need to pull the values from the table like:
local getSuccess, Result = pcall(function()
return Store:GetAsync(playerUserID)
end)
if getSuccess then
local Coins = Result.Coins
local Future = Result.Future
-- Continue this for the other values
end
Or instead of pulling out each variable, you can just use the table directly:
player.Leaderstats.Coins.Value = Result.Coins
player.Leaderstats.Swords.FutureSword.Value = Result.Future
-- Continue for the other vlaues
local DataStoreService = game:GetService("DataStoreService")
local Store = DataStoreService:GetDataStore("Storage")
game.Players.PlayerRemoving:Connect(function(player)
local playerUserID = player.UserId
local Coins = player.Leaderstats.Coins.Value
--bools
local Future = player.Leaderstats.Swords.FutureSword.Value
local Light = player.Leaderstats.Swords.LightSword.Value
local Dark = player.Leaderstats.Swords.DarkSword.Value
local Demon = player.Leaderstats.Swords.DemonSword.Value
local Doom = player.Leaderstats.Swords.DoomSword.Value
--end bools
local setSuccess, errorMessage = pcall(function()
Store:SetAsync(playerUserID, {
Coins = Coins,
Future = Future,
Light = Light,
Dark = Dark,
Demon = Demon,
Doom = Doom
})
end)
if not setSuccess then
warn(errorMessage)
end
end)
game.Players.PlayerAdded:Connect(function(player)
local playerUserID = player.UserId
local getSuccess, Result = pcall(function()
return Store:GetAsync(playerUserID)
end)
if getSuccess then
local Coins = Result.Coins
local Future = Result.Future
local Light = Result.Light
local Dark = Result.Dark
local Demon = Result.Demon
local Doom = Result.Doom
end
end)