I was creating a dataStore script and suddenly when I tested the game on server mode, the game crashes after about 5-10 seconds. I can't use the devConsole because the serverSide cleared. Here's the datastore code.

--SAVE


function Enter(plr)
	plr:WaitForDataReady()
	
	local DS = game:GetService("DataStoreService"):GetDataStore("STATS")
	local l=DS:GetDataStore(plr.UserId.."_GEMS")
	
	plr.leaderstats.Gems.Value=l
	

		
		plr.leaderstats["Blue Coins"].Value=DS:GetAsync(plr.userId.."_BCOINS")
		

	
	ge=plr.Gems:GetChildren()
	
	for i=1,#ge do
		ge[i].Value=DS:GetAsync(plr.userId.."_GEM_"..i)
	end
	
	bc=plr.BCoins:GetChildren()		
		
	for i=1,#bc do
		bc[i].Value=DS:GetAsync(plr.userId.."_BC_"..i)
	end
end

function Exit(oplr)

	local DS = game:GetService("DataStoreService"):GetDataStore("STATS")

	ge=oplr.Gems:GetChildren()
	DS:SetAsync(oplr.userId.."_GEMS",oplr.leaderstats.Gems.Value)
DS:SetAsync(oplr.userId.."_BCOINS",oplr.leaderstats["Blue Coins"].Value)


	
	
	for i=1,#ge do
		DS:SetAsync(oplr.userId.."_GEM_"..i,oplr.Gems.i.Value)
	end
	
	bc=oplr.BCoins:GetChildren()		
	
	for i=1,#bc do
		DS:SetAsync(oplr.userId.."_BC_"..i,oplr.BCoins.i.Value)
	end

end

game.Players.PlayerAdded:connect(Enter)
game.Players.PlayerRemoving:connect(Exit)

Now, could this have anything to do with the number of asyncs created? I will peovide any more scripts if needed.

Here's the game link.

http://www.roblox.com/games/292183989/Pencils-Place-Number-86

All thanks in advance!

4 comments

0

You are trying to get a 'DataStore' on line 8 from a 'DataStore' you defined at line 7. I never tried this before, but it shouldn't be possible! Maybe you meant to put ':GetAsync' at line 8?

0

Worked, thanks!

0

;-; it still doesn't save the gem and BCoin indexes

0

Well, I can see other problems as well. At line 21, 27, 43 and 49 you use concatenation of string to number. Use '..tostring(i)' instead of '..i'. Also, at lines 43 and 49, change '.i.Value' with ':FindFirstChild(tostring(i)).Value)'