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

What's wrong with this?

Asked by 10 years ago

I haven't fiddled with Data Store that much and I'm terrible at anything to do with BrickColors but I'm still pretty unsure why this is broken The main parts of the script are:

doba = script.Parent.Parent.Parent
ds = game:GetService("DataStoreService"):GetGlobalDataStore()

color = ds:GetAsync(player.userId .."currentpants") or nil -- problem occurs around here
if color == nil then
    ds:SetAsync(player.userId .."currentpants",tostring(script.Parent.Parent.Parent.stats.lleg.Value))
    color = tostring(script.Parent.Parent.Parent.stats.lleg.Value) -- should be bright blue
script.Parent.Parent.Parent.stats.lleg.Value =
script.Parent.Parent.Parent.stats.rleg.Value =

rleg & lleg are BrickColorValues

Any solutions?

EDIT: changed

color = ds:GetAsync(player.userId .."currentpants")
color = ds:GetAsync(player.userId .."currentpants") or nil

still broken!

What is the error you get? FromLegoUniverse 264 — 10y
I can't check, it runs in online mode. drager980 5 — 10y

1 answer

Log in to vote
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

I asked a similar question a little bit ago.

It turns out, GetAsync doesn't return nil when called for an empty key. In fact, it literally returns nothing at all.

To fix this, change line 5 to this:

color = ds:GetAsync(player.userId .."currentpants") or nil

That creates a default value to work with.

Also, you can't test DataStores using a Test Server, you have to do it on a live server from the Play button.

This is great but it isn't the only error in the script, it still breaks. drager980 5 — 10y

Answer this question