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

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
script.Parent.Parent.Parent:WaitForDataReady()
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
end
script.Parent.Parent.Parent.stats.lleg.Value = BrickColor.new(color)
script.Parent.Parent.Parent.stats.rleg.Value = BrickColor.new(color)

rleg & lleg are BrickColorValues

Any solutions?

EDIT: changed

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

still broken!

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

1 answer

Log in to vote
2
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.

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

Answer this question