Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Data Storage Not Working Have Code?

Asked by 6 years ago

I have this but it does not seem to store any data.

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("AbilitySaveSystem")
print(ds)

game.Players.PlayerAdded:Connect(function(player)
 print(player.userId)   
 local Power = Instance.new("StringValue",player)
 Power.Name = "Power"
 print(ds:GetAsync(player.userId))
 if ds:GetAsync(player.userId) ~= "None" then
    Power.Value = ds:GetAsync(player.userId)
    print("He had an ability")
else    
 Power.Value = "None"
 print("He had no ability")
end
 ds:SetAsync(player.userId, Power.Value)
 Power.Changed:Connect(function()
  ds:SetAsync(player.userId, Power.Value)
  print("Updated Ability: ".. ds:GetAsync(player.userId))
 end)
end)


game.Players.PlayerRemoving:Connect(function(player)
print("Bye")
 ds:SetAsync(player.userId, player.Power.Value)
 print("Successfuly saved "..player.userID..": "..ds:GetAsync(player.userID))
end)
0
Why are you calling GetAsync like 10 times in the PlayerAdded User#19524 175 — 6y
0
I called it in the prints for me to check if it would print out in the console and I don't really know how to type it better. But it always defaults to the else as it finds the ability to always be None webman42 0 — 6y

1 answer

Log in to vote
1
Answered by
Donut792 216 Moderation Voter
6 years ago

this is my method of using regular datastores it works pretty well for me

local Data = game:GetService("DataStoreService"):GetDataStore("AbilitySaveSystem")
game.Players.PlayerAdded:Connect(function(player)
    local Power = Instance.new("StringValue") -- i think using instance parent is deprecated so i didnt use it here
    Power.Name = "Power"
    Power.Parent = player
print("Gave "..player.Name.." Power Data")

    local SavedItems = Data:GetAsync(player.UserId) -- userId is Deprecated use UserId
    if SavedItems then
        Power.Value = SavedItems.Power or "None"
        print(player.Name.." had Power data")
    else
        Power.Value = "None"
        print(player.Name.." didn't have Power data")
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local Saving = {["Power"] = (player.Power).Value;
        }
    Data:SetAsync(player.UserId, Saving)
    print("Saved "..player.Name.."'s Power Data")
end)
0
Hey, I appreciate the help but I seems the script still has problems. Let me go more in depth. I have system that if your role is none and you click on this altar you roll an ability, in this case I rolled ShadowStep. I then end the testing and hit play yet the ability reverts back to none. Am I missing something else? Sorry about the trouble just now to Lua I do python and java. webman42 0 — 6y
Ad

Answer this question