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

GetAsync is not a valid member of datastoreservice?,help!

Asked by
enes223 327 Moderation Voter
5 years ago

I'm trying to a script that checks if player has that in data but its not working! heres script:

local DS = game:GetService("DataStoreService")
local NewPlayerValueName = "NewPlayer"
local RS = game:GetService("ReplicatedStorage")
local Remote = RS.TutorialFinish

game.Players.PlayerAdded:Connect(function(plr)
    if DS:GetAsync("TFinish")[plr.Name] then
        plr.PlayerGui.Finish.Visible = false
        plr.PlayerGui.Tutorial.Visible = false
        plr.PlayerGui.Tutorial2.Visible = false
        plr.PlayerGui.Tutorial3.Visible = false
    end
end)

Remote.OnServerEvent:connect(function(plrname)
    DS:SetAsync("TFinish",{plrname})
end)

thx for looking...

0
Im confused why you made a variable thats longer than what it holds. DinozCreates 1070 — 5y
0
GetAsync is a function of GlobalDataStore which you get by DataStoreService:GetDataStore(unique_key) GoldAngelInDisguise 297 — 5y
0
maybe he wanted to use it multiple times but if not, lol GoldAngelInDisguise 297 — 5y
0
oh k xd enes223 327 — 5y
View all comments (5 more)
0
Unless your GUI was made by the server this wont work. DinozCreates 1070 — 5y
0
Even if using something multiple times you'd still have to type more in the end. DinozCreates 1070 — 5y
0
local abcdefg = "abc" -- super gross and inefficient DinozCreates 1070 — 5y
0
if he were to want to change the value in the future it would only be once GoldAngelInDisguise 297 — 5y
0
Well he didnt even use it lol. DinozCreates 1070 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

In order to use datastores, you must require the service which you have done local DS = game:GetService("DataStoreService") and then from the datastore service, get the specific datastore you are looking for. For instance local MyDataStore = DS:GetDataStore('Datastore name here'), in which you are then looking inside of a datastore rather than looking in the service itself.

You should also make sure you are looking at a specifc players data when :GetAsync or otherwise it will be the same for all users. You can do this by adding in a prefix when you :GetAsync, for example MyDataStore:GetAsync(plr.UserId.."TFinish").

By adding in a prefix you must also change the saving process. I have edited this below.

Here is the updated code that should work:

local DS = game:GetService("DataStoreService")
local MyDataStore = DS:GetDataStore('Infomation')
local NewPlayerValueName = "NewPlayer"
local RS = game:GetService("ReplicatedStorage")
local Remote = RS.TutorialFinish

game.Players.PlayerAdded:Connect(function(plr)
        if MyDataStore:GetAsync(plr.UserId.."TFinish") then
            plr.PlayerGui.Finish.Visible = false
            plr.PlayerGui.Tutorial.Visible = false
            plr.PlayerGui.Tutorial2.Visible = false
                plr.PlayerGui.Tutorial3.Visible = false
        end
    end)

    Remote.OnServerEvent:connect(function(plrname)
        MyDataStore:SetAsync(plrname.UserId.."TFinish", true)
    end)

I hope you also realise that by firing the Remote Event the Frames .Visible value will not change as it only works when the player joins the server, or rejoins for that matter.

0
thanks enes223 327 — 5y
Ad

Answer this question