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

How do I use DataStores upon entry of game?

Asked by
Dad_Bot 34
6 years ago

I am making a game where I need the player to view a cutscene the first time they enter. I am trying to use DataStores to store whether they viewed it or not. However, nothing I'm trying seems to be working. The wiki isn't clear to me and I can't figure out how to use this DataStore system. What would any of you suggest to help me overcome this issue and only play the cutscene when the player first joins.

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

Something like this should work:

local hasJoinedStore = game:GetService("DataStoreService"):GetDataStore("HasJoined")
game.Players.PlayerAdded:Connect(function(plr)
    local hasJoined = hasJoinedStore:GetAsync("plr_" .. plr.UserId)
    if not hasJoined then
        --do stuff if first time
        hasJoinedStore:SetAsync("plr_" .. plr.UserId,true)
    end
end)
Ad

Answer this question