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

What's wrong with this?

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!

2 comments

0

What is the error you get?

0

I can't check, it runs in online mode.

1 answer

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.

1 comment

0

This is great but it isn't the only error in the script, it still breaks.

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