Why my datastore don't work?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Hello, i am new with DataStoreService, so i tried alone and without tutorials other than the from Roblox.

  2. What is the issue? Include screenshots / videos if possible!
    Ok, so i am trying to make a IntroGui that will be played if a player was come in the Server the first time, but i don’t know why but it simply not store my boolean. I have a Textbutton, and when you press on it it will change a BooleanValue that it was located in a Folder. The problem was not on getting the data, but on saving it, then when i print out my Value with the MouseButton1Event it say me true, but when i stop to test in studio and see the output it say me false. Why? Really not understand and need help!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Yes, but it the Topics i found not really helped me.
My script:

local DataStore = game:GetService("DataStoreService")
local CanBeginData = DataStore:GetDataStore("CanBegin")

local function CommonInstance(Type, Parent, Name)
	local InstanceByFunc = Instance.new(Type)
	InstanceByFunc.Parent = Parent
	InstanceByFunc.Name = Name
	return InstanceByFunc
end



game.Players.PlayerAdded:Connect(function(player)
	local CanBeginValue
	local function CanBeginnFunction() => boolean
		CanBeginValue = CanBeginData:GetAsync(player.Name.."_CanBegin")
		if CanBeginValue == nil then
			CanBeginData:SetAsync(player.Name.."_CanBegin", false)
			CanBeginValue = false
		end
		return CanBeginValue
	end
	
	local CanBeginnSuccess, CanBeginReturnValue = pcall(CanBeginnFunction)

	print(player.Name.." has entred the game!")
	
	if CanBeginnSuccess then
		local MenuValues = game.ReplicatedStorage.States.MenuValues
		local PlayerMenuValues = CommonInstance("Folder", MenuValues, player.Name.."'s MenuValues")
		local CanBegin = CommonInstance("BoolValue", PlayerMenuValues, "CanBegin")
		CanBegin.Value = CanBeginValue
	else
		print(CanBeginReturnValue)
		player:Kick("Error message:"..CanBeginReturnValue..". For avoiding Datalost and others problems you will be disconnected. Sorry for this unexepted error and retry later else contact me.")
	end
end)



game.Players.PlayerRemoving:Connect(function(player)
	local CanBeginSucces, CanBeginReturnValue = pcall(function()
		local MenuValues = game.ReplicatedStorage.States.MenuValues
		CanBeginData:SetAsync(player.Name.."_CanBegin", MenuValues[player.Name.."'s MenuValues"].CanBegin.Value)
	end)
end)
1 Like

So I’m assuming you want to show the intro gui when the player joins the game for the first time ever, not the server.
I’m not sure where you’d put the intro code, but I’m guessing you’re going to make it depend on the CanBegin.Value being true.

Now, the problem here is, you never set CanBegin.Value to anything other than nil or false!!!

In this particular function, I believe your intention was to set CanBeginValue = true after the SetAsync call, like this:

local function CanBeginnFunction() => boolean
    CanBeginValue = CanBeginData:GetAsync(player.Name.."_CanBegin")
    if CanBeginValue == nil then
        CanBeginData:SetAsync(player.Name.."_CanBegin", false)
        CanBeginValue = true
    end
    return CanBeginValue
end

(btw you don’t have to save the value again on PlayerRemoving if you only want the intro to be played once and don’t have any way to change the value in game i.e. with a settings gui)

1 Like

@Amiaa16, i placed my script into the ServerScriptService. Then i use this:

Then if the Data newer was created, also nil, then i will create the new Data value with the SetAsync and not, i not want to use CanBeginValue = true, then if the Value was nil, then i need to create a new Value, and this is b default false, as this was the first time that a player enter in the game.

Yes, sorry for misstake.

No, you are wrong. When i click on the Gui the Value change to true and i self see that.

I resolved the problem with using the Remotes events and server side.