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

why doesnt datastore work but other datastores in the same exact format does?

Asked by 6 years ago

Im trying to make a datastore. I know that this script works, but when i go to make it save a different value, it errors out and i have no idea. Why?

local currencyName = "Company1PromotionCurrent"

local DataStore = game:GetService("DataStoreService"):GetDataStore("Company1PromotionCurrent")
game.Players.PlayerAdded:Connect(function(player)
    wait(1)
    local currency = player:WaitForChild("PlayerValues"):WaitForChild("OtherValues"):WaitForChild("CompanyValues"):WaitForChild("PromotionCurrent").Value
    local ID = currencyName.."-"..player.UserId
    local savedData = nil
    pcall(function()
        savedData = DataStore:GetAsync(ID)
    end)
    if savedData ~= nil then
        currency.Value = savedData
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local ID = currencyName.."-"..player.UserId
    DataStore:SetAsync(ID,player.PlayerValues.OtherValues.CompanyValues:FindFirstChild("PromotionCurrent").Value)
end)

1 answer

Log in to vote
1
Answered by 6 years ago

Yoyoyoyoyoyoyoo I use to have this problem. U wanna know why? Its because when you load in, if you have previously used that datastore you will be loading a different type of value then its like.. "Bro... what da heck.. You just saved me as a boolean but now you are trying to change me into a integer? Get lost..".

I hope that explained it. To fix it either change the name of the datastore into something where u dont have any values saved yet. Orrrr, just make the value into nothing, and just let it be then make different values. If this is confusing contact my discord getzum#9659

I had this problem and I never knew why but after a month I was like... oh.. yeah im dumb.

Ad

Answer this question