Hello,
I am trying to save a custom name to the player… I am currently using DATASTORE2 and NOT the ROBLOX DataStore.
The problem is, whenever I join the game, it gives me a random name (like its supposed to), but that name doesn’t save at all; Whenever I rejoin the game, it gives me a new name.
I have issues using DataStores, so help would be appreciated.
Setting Data Script:
local ds2 = require(game.ReplicatedStorage.DataStore2)
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local clonedInfo = info:Clone()
clonedInfo.Parent = char:WaitForChild("Head")
clonedInfo.Adornee = char:WaitForChild("Head")
clonedInfo.ActualName.Text = "@" .. plr.Name
local store = ds2("NamesAndStuff",plr)
local randomName = firstNames[math.random(1,#firstNames)] .. " " .. lastNames[math.random(1,#lastNames)]
store:Set(randomName)
clonedInfo["Name[Custom]"].Text = store:Get(randomName)
end)
end)
(firstNames and lastNames are defined)
Saving Data Script:
game.Players.PlayerAdded:Connect(function(plr)
local dataFolder = Instance.new("Folder",plr)
dataFolder.Name = "DATA"
local name = Instance.new("StringValue",dataFolder)
name.Name = "Name"
local store = ds2("NamesAndStuff",plr)
name.Value = store:Get("None")
store:OnUpdate(function(new)
name.Value = new
store:Save()
end)
end)