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?
01 | local currencyName = "Company1PromotionCurrent" |
02 |
03 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "Company1PromotionCurrent" ) |
04 | game.Players.PlayerAdded:Connect( function (player) |
05 | wait( 1 ) |
06 | local currency = player:WaitForChild( "PlayerValues" ):WaitForChild( "OtherValues" ):WaitForChild( "CompanyValues" ):WaitForChild( "PromotionCurrent" ).Value |
07 | local ID = currencyName.. "-" ..player.UserId |
08 | local savedData = nil |
09 | pcall ( function () |
10 | savedData = DataStore:GetAsync(ID) |
11 | end ) |
12 | if savedData ~ = nil then |
13 | currency.Value = savedData |
14 | end |
15 | end ) |
16 |
17 | game.Players.PlayerRemoving:Connect( function (player) |
18 | local ID = currencyName.. "-" ..player.UserId |
19 | DataStore:SetAsync(ID,player.PlayerValues.OtherValues.CompanyValues:FindFirstChild( "PromotionCurrent" ).Value) |
20 | end ) |
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.