Trying to save login data

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

  1. What do you want to achieve? So im trying to make a sign up thingy so you type your name in for the account name and password and when you click create account it saves data so when you login it can see if that is a real account.

  2. What is the issue? I have no idea how to do it lmao ._.

  3. What solutions have you tried so far? used discord webhooks so it sends the account name so i can manually make the account.

also i think i have covid

1 Like

Well, discord webhooks blocked Roblox API a while ago. You could save this in datastore, but the topic is a little concerning. Why are you having them sign up? Is it clear it’s not to phish passwords?

im trying to make a game like nitrotype

i ment that when it checks if its a real account i ment a account that has been made in the game, I understand why you think it was concerning. Its trying to check if the account exists in the game.

Gotcha - Nitro type needs people to sign up so they can access the platform and save data, with Roblox you’d already be able to reference their Roblox UserID for saving and all that. Would that work instead? Might just be an easier solution than having your own gatekeeper to play is why I ask.

im trying to make it so people could make it custom names like: “HotDogs4Life” etc. So it wouldnt be much fun with a race with regular names.

This is my Sign-Up page ive made.

Ok! Nicknames would also be something you could save with datastores. You could pursue the password-based system, but it would be an unnecessary step when you would reference the datastore with the players’ UserID anyways, so you’d know if they had a save or not. It’d also be complicated when a player forgets their password, and questionable legality/security since you would be potentially handling someones’ confidential info in plaintext.
Your table to update the datastore might start out looking something like:

local save = {
	nickname = ""
}

Then you would create a DataStore (say, one named “playerSaves”) and set a key (the players’ UserId) to have “save” as a value.

1 Like

I dont really understand data stores, so is this probally a start of the dataStore? ``` local DataStoreService = game:GetService(“DataStoreService”)
local AccountsData = DataStoreService:GetDataStore(“Accounts”)

game.Players.PlayerAdded:Connect(function(player)

end) ```

2 Likes

Yep, you are on the right track. Within the PlayerAdded event you’d fetch their data from AccountsData. Such as:

game.Players.PlayerAdded:Connect(function(player)
	local success, data = pcall(function()--When dealing with datastores, always wrap in pcalls
		return AccountsData:GetAsync(player.UserId)
	end)
	
	if success then
		print("Save found:")
		print(data)
	else
		print("No save!")
	end
end)

If we get the login/sign-up thing working, Im def crediting you in the description

it said save found but than said the data is nil 18:17:35.914 Save found: - Server - leaderstats:10 18:17:35.914 nil - Server - leaderstats:11

1 Like

yes, because you don’t have any data on the datastore :slight_smile:

how would i add data to the data store exactly?

local Success, ErrorMessage = pcall(function()
    YourDataStore:SetAsync(Player.UserId, {User = 'User', Password = 'Password'})
end)

if Success then
    -- Bla bla bla
else
    print(ErrorMessage);
end

Aye - the datastore was successfully fetched from, but you’ve not put anything into it, so it will return nil. “success” catches the error that the datastore could not be reached, which could be a disaster, so we wrap it in a pcall.

To add something to the datastore you’d want to use either SetAsync or UpdateAsync. The latter is always recommended for preventing data loss, but SetAsync is easier explained, so we will start with that. This one returns “success” and an error message rather than data, so printing the error message will give a clue as to the problem it had setting a datastores’ key. For your app it will look something like this:

local save = {
	nickname = "Hello World!"
}

local success, errorMessage = pcall(function()
	AccountsData:SetAsync(player.UserId, save)
end)

if not success then
	print(errorMessage)
end
1 Like

this is my create account script would this work?: ``` local DataStoreService = game:GetService(“DataStoreService”)
local AccountsData = DataStoreService:GetDataStore(“Accounts”)

local NameEnterBtn = script.Parent.EnterName
local SubmitNameBtn = script.Parent.SubmitName
local TextName = script.Parent.TextName
local Text = “Enter your username here.”
local ReplicatedStorage = game.ReplicatedStorage
local RegUsersFolder = ReplicatedStorage.RegisteredUsers
script.Parent.Continue.Visible = false

local player = game.Players.LocalPlayer

SubmitNameBtn.MouseButton1Click:Connect(function()

if not string.len(NameEnterBtn.Text) ~= 8 then
	if not RegUsersFolder:FindFirstChild(NameEnterBtn.Text) then

		TextName.Text = "Your account named: " .. NameEnterBtn.Text .. " has now been registered."
		local save = {
			nickname = NameEnterBtn.Text
		}

		local success, errorMessage = pcall(function()
			AccountsData:SetAsync(player.UserId, save)
		end)

		if not success then
			print(errorMessage)
		end
	else
		script.Parent.Continue.Visible = false
		TextName.Text = "Were sorry, but that account called " .. NameEnterBtn.Text .. " has already been registered. Please try again with a different name."
		wait(5)
		TextName.Text = Text
	end
else
   NameEnterBtn.Text = "Text must be less than 8 Characters!"
end

end) ```

oh wait it errored DataStore can't be accessed from client - Client - new:2

server script:

local AccountsData = DataStoreService:GetDataStore("Accounts")

game.Players.PlayerAdded:Connect(function(player)
	local success, data = pcall(function()
		return AccountsData:GetAsync(player.UserId)
	end)

	if success then
		print("Save found:")
		print(data)
	else
		print("No save!")
	end
	
	game.ReplicatedStorage.ChangeData.OnServerEvent:Connect(function(data)
		local success, errorMessage = pcall(function()
			AccountsData:SetAsync(player.UserId, data)
		end)

		if not success then
			print(errorMessage)
		end
	end)
end)


local script (create Account script):

local SubmitNameBtn = script.Parent.SubmitName
local TextName = script.Parent.TextName
local Text = "Enter your username here."
local ReplicatedStorage = game.ReplicatedStorage
local RegUsersFolder = ReplicatedStorage.RegisteredUsers
script.Parent.Continue.Visible = false

local player = game.Players.LocalPlayer

SubmitNameBtn.MouseButton1Click:Connect(function()
	
	if not string.len(NameEnterBtn.Text) ~= 8 then
		if not RegUsersFolder:FindFirstChild(NameEnterBtn.Text) then

			TextName.Text = "Your account named: " .. NameEnterBtn.Text .. " has now been registered."
			local save = {
				nickname = NameEnterBtn.Text
			}
			
			game.ReplicatedStorage.ChangeData:FireServer(save)
		else
			script.Parent.Continue.Visible = false
			TextName.Text = "Were sorry, but that account called " .. NameEnterBtn.Text .. " has already been registered. Please try again with a different name."
			wait(5)
			TextName.Text = Text
		end
	else
	   NameEnterBtn.Text = "Text must be less than 8 Characters!"
	end
	
	
end)

error: 18:32:51.919 104: Cannot store Instance in data store. Data stores can only accept valid UTF-8 characters. - Server - leaderstats:22

1 Like

so does this mean it has to be like the letter number like example hi = 89