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

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

Asked by
H4X0MSYT 536 Moderation Voter
6 years ago
Edited 6 years ago

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
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. User#5423 17 — 6y
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 H4X0MSYT 536 — 6y
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. H4X0MSYT 536 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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).

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. H4X0MSYT 536 — 6y
0
* Still get kicked with or without Data2 H4X0MSYT 536 — 6y
Ad
Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago

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

Answer this question