Context So for one of my games I made a character login that supports multiple unique characters(unique as in everyone has their own individual names, E.G only one 'LeToucan' is allowed). What I currently have is you enter the name of the character, and it logs you onto that character. Note this is in multiple scripts that it does this.

Registration

script.Parent.OnServerEvent:connect(function(player1,arg)
local key = "Owner"
local key2 = player1.UserId
local lower = string.lower(arg)
local firstletter = string.upper(string.sub(lower,1,1))
local finalstring = ""..firstletter..""..string.sub(lower,2)..""
local datas=game:GetService"DataStoreService":GetDataStore(finalstring, "Name")
	if(arg:match("%a")) and not(arg:match("%d")) then
        wait()
		if string.len(finalstring) >= 12 then
		game.Workspace.RemoteEvents.GloballyText.Value = ("Character "..finalstring.." is too long!")
		wait()
		print(game.Workspace.RemoteEvents.GloballyText.Value)
		elseif string.len(finalstring) <= 2 then
		game.Workspace.RemoteEvents.GloballyText.Value = ("Character "..finalstring.." is too short!")
		wait()
		print(game.Workspace.RemoteEvents.GloballyText.Value)
		else-- Check if datas is available
		if datas:GetAsync(key) == player1.UserId then
		game.Workspace.RemoteEvents.GloballyText.Value = ("Character "..finalstring.." is already yours!")
		wait()
		print(game.Workspace.RemoteEvents.GloballyText.Value)
		elseif datas:GetAsync(key)~= nil then
		game.Workspace.RemoteEvents.GloballyText.Value = ("Character "..finalstring.." has already been claimed!")
		wait()
		print(game.Workspace.RemoteEvents.GloballyText.Value)
		elseif player1.Characters.Value >= 3 then
		game.Workspace.RemoteEvents.GloballyText.Value = ("You already have 3 characters! You cannot make any more!")
		wait()
		print(game.Workspace.RemoteEvents.GloballyText.Value)
		else
		player1.Characters.Value = player1.Characters.Value + 1
        datas:UpdateAsync(key, function(oldValue) 
	    return player1.UserId; end)
		game.Workspace.RemoteEvents.GloballyText.Value = ("Player name "..finalstring.. " has been created by "..player1.Name.."! You can now login with "..finalstring.."!")
		wait()
		print(game.Workspace.RemoteEvents.GloballyText.Value)
		end -- Name Checker
		end -- string.len
	    else
		game.Workspace.RemoteEvents.GloballyText.Value = ("Only uppercase/lowercase letters!")
		wait()
		print(game.Workspace.RemoteEvents.GloballyText.Value)
	end -- arg:match
end)

So basically that just checks if it fills the requirements(E.G too long/short name, already taken, etc) and creates it if it passes all of them.

Login

script.Parent.OnServerEvent:connect(function(player1,arg)
local key = "Owner"
local key2 = "Stats"
local lower = string.lower(arg)
local firstletter = string.upper(string.sub(lower,1,1))
local finalstring = ""..firstletter..""..string.sub(lower,2)..""
local datas=game:GetService"DataStoreService":GetDataStore(finalstring, "Name")
	if(finalstring:match("%a")) and not(finalstring:match("%d")) then
		if string.len(finalstring) >= 12 then
		game.Workspace.RemoteEvents.GloballyText.Value = ("Character "..finalstring.." is invalid!")
		wait()
		print(game.Workspace.RemoteEvents.GloballyText.Value)
		elseif string.len(finalstring) <= 2 then
		game.Workspace.RemoteEvents.GloballyText.Value = ("Character "..finalstring.." is invalid!")
		wait()
		print(game.Workspace.RemoteEvents.GloballyText.Value)
		else
		if datas:GetAsync(key) == player1.UserId then
		local teemomain=game:GetService"DataStoreService":GetDataStore(finalstring, "PlayerTrack")
		local teemokey = finalstring
		game.Workspace.RemoteEvents.GloballyText.Value = ("Welcome "..finalstring.."! We are logging you in, please wait.")
		wait(2.5)
		print(game.Workspace.RemoteEvents.GloballyText.Value)
		game.Workspace.RemoteEvents.LogLoadKappa.Value = true
		wait(1)
		game.Workspace.RemoteEvents.GloballyText2.Value = ("Loading Assets for "..finalstring.."...")
		print("Assets Loading")
		wait(.5)
		local stat=player1
		local datas=game:GetService"DataStoreService":GetDataStore(finalstring)
		if datas:GetAsync(key)==nil then
			datas:SetAsync(key,{"Mercenary"}) 
		end
		local CardStore = Instance.new("Folder")
		CardStore.Parent = player1
		CardStore.Name = "COData"
		local taaa = datas:GetAsync(key)
        for i,v in pairs(taaa) do
        wait()
        Plane = Instance.new("ObjectValue")
        Plane.Parent = CardStore
        Plane.Name = v
        end
		player1:LoadCharacter()
		game.Workspace.RemoteEvents.GloballyText2.Value = ("Loading Data for "..finalstring.."...")
		wait(.5)
		print("Data Loading")
		elseif datas:GetAsync(key) ~= player1.UserId then
		game.Workspace.RemoteEvents.GloballyText.Value = ("Character "..finalstring.." does not belong to you!")
		wait()
		print(game.Workspace.RemoteEvents.GloballyText.Value)
		elseif datas:GetAsync(key) == nil then
		game.Workspace.RemoteEvents.GloballyText.Value = ("Character "..finalstring.. " does not exist!")
		wait()
		print(game.Workspace.RemoteEvents.GloballyText.Value)
		end -- Name Checker
		end -- string.len
	    else
		game.Workspace.RemoteEvents.GloballyText.Value = ("Character "..finalstring.." is invalid!")
		wait()
		print(game.Workspace.RemoteEvents.GloballyText.Value)
	end -- arg:match
end)

So the login just loads/creates the data(if it doesn't exist).

All of it works(I didn't add the local scripts - they're simple enough.)

What I want to do I basically want to make a 'list' of all the characters. It doesn't have to be selectable or anything - just a list that the player can read so that they know what characters/names they own.

Any ideas?

Also regarding any of the comments on the scripts I just leave them there to remember various things - I'm a super messy coder.

1 comment

0

I think using DataStores would work the best. Use their Username as a key, and have Strings for Data, if that makes sense. http://wiki.roblox.com/index.php?title=API:Class/GlobalDataStore