Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[CLOSED] Datastore Error: Cannot cast value to object?

Whenever I run my data script to obviously save and load things, I made functions to go through and load data, then made a function to be called multiple times and load, but anyway, thats not related. Using this script, I, the player is kicked from the game as the script does. Although it shouldnt..? This may be an incredibly stupid mistake... It's stumped me because the whole game relies on this.

function LoadItem(Data2,DataType,PlayerID, Parent, Player)
	local F
	local Scope = "Player_" .. PlayerID
	local Data = DataStore:GetDataStore("Data", Scope)
	if DataType == "Number" then
		F = Instance.new("NumberValue", Parent)
	elseif DataType == "Int" then
		F = Instance.new("IntValue", Parent)
	elseif DataType == "String" then
		F = Instance.new("StringValue", Parent)
	elseif DataType == "Bool" then
		F = Instance.new("BoolValue", Parent)
	end
	F.Name = Data2
	repeat
		Tries = Tries + 1
		local Sucess, Temp = pcall(function()
			return Data:GetAsync(Data)
		end)
		if not Success then wait(1) end
	until Tries == ALLOWED_RETRIES or Success
	if not Success then
		PWE:FireClient(Player, "Warn", "ROBLOX's DataStoreService may be offline. Please try again later. We have kicked you to prevent you losing your data.")
		wait(2)
		Player:Kick("ROBLOX's DataStoreService may be offline. Please try again later. We have kicked you to prevent you losing your data.")
	end
	F.Value = Temp
	Temp = nil
end

3 comments

0

This is not how you use a data store at all. The scope is used to to structure the data stores in more meaning full groups. It it not meant to create a data store per player.

0

Ok go ahead. Question the work of those who are chosen to write to the roblox wiki.. Yeah seems legit that it's wrong.... You haven't even seen it. http://wiki.roblox.com/index.php?title=Data_store

0

Question it all you want. I can structure it how I want. I'll follow the wiki, written by those chosen by roblox itself.

2 answers

return Data:GetAsync(Data) is wrong (should it be return Data:GetAsync(Data2) ?). To prevent such errors in the future, consider logging/printing out whatever 'Temp' is -- it is the error message when 'Success' is false.

Note that it would be more efficient if you loaded/saved a single table with all the needed values instead of loading/saving to several different keys per player (especially since there are limits on how frequently you can load/save a single key (see limitations here: http://wiki.roblox.com/index.php?title=Data_store). So long as the table isn't huge (and either only uses string keys or is a list), it will save/load correctly (and will only count as 1 request).

2 comments

0

I think i had accidentally deleted Data2, but Still get kicked :/ Doesn't fix it for me... Also I will use tables, but currently im using a number value so lets say i need to roll back or modify data contents, i can run extra functions to modify it in cases of events or something.

0
  • Still get kicked with or without Data2

facepalm it was a spelling mistake... Success was spelt wrong ...

This discussion is preserved as it was. New answers, comments, and votes are closed.