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

Why is my data store broken?

I have a script that shows you a tutorial GUI if its your first time playing. I could only think of using data stores to do this.

The player can click "Never show this again" which sets a value in the player to 1 (I tried to update the data store directly but it couldn't be accessed from the client)

The script works fine when you rejoin the game after clicking "Never show this again". The tutorial doesnt appear.

However on the 3rd visit, the gui shows again, and the value "TutorialComplete" no longer exists in the player... This is what happens on each visit. It repeats.

1st - See GUI, click "Never show this again" 2nd - No GUI 3rd - GUI reappears

local DataStore = game:GetService("DataStoreService"):GetDataStore("Tutorial")

game.Players.PlayerAdded:connect(function(player)
	local key = "user_"..player.userId
	Tutorial = Instance.new("NumberValue", player)
	Tutorial.Name = "TutorialCompleted"
	
	
	if DataStore:GetAsync(key) == nil or DataStore:GetAsync(key)==0 then
		Tutorial.Value = 0
		game.ServerStorage.Tutorial:Clone().Parent = player.PlayerGui	
	elseif 	DataStore:GetAsync(key) == 1 then
		print("It was 1")
	end

end)

game.Players.PlayerRemoving:connect(function(player)
	local key = "user_"..player.userId
	DataStore:SetAsync(key,player.TutorialCompleted.Value)

end)

1 answer

You reset Tutorial.Value to 0 at the end of the script because if key is 1 then it never sets tut.val to 1.

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