Hello there, thank you for reading. I am making a game where you can name your character and it saves, but the code won't save the name for some reason. It used to work, I got it from a Youtuber, and I have messed around with it, but it's still not working. It will change the player's "name," which is basically just changing a Billboard GUI's text above the player's head, but it won't save it.
Script in ServerScriptService:
local textServ = game:GetService("TextService") local DataStore = game:GetService("DataStoreService") local NameStore = DataStore:GetDataStore("RPNames") game.Players.PlayerAdded:Connect(function(plr) local rpData = Instance.new("Folder") rpData.Name = "RPData" local rpName = Instance.new("StringValue") rpName.Name = "RPName" rpName.Value = NameStore:GetAsync(plr.UserId) or "" rpName.Parent = rpData rpData.Parent = plr plr.CharacterAdded:Connect(function(char) wait(0.2) local head = char:FindFirstChild("Head") if head then print("HEAD") local over = head:FindFirstChild("PlayerOverhead") if over then local text = over.TextLabel if(plr.RPData.RPName.Value ~= "") then text.Text = plr.RPData.RPName.Value else text.Text = plr.Name end end end end) plr.RPData.RPName.Changed:Connect(function() local head = plr.Character:FindFirstChild("Head") if head then print("HEAD") local over = head:FindFirstChild("PlayerOverhead") if over then local text = over.TextLabel text.Text = plr.RPData.RPName.Value end end end) end) game.ReplicatedStorage.ChangeRPName.OnServerEvent:Connect(function(plr, name) local filteredObject local filteredText local success, err = pcall(function() filteredObject = textServ:FilterStringAsync(name, plr.UserId) end) if(success) then local complete, failed = pcall(function() filteredText = filteredObject:GetNonChatStringForBroadcastAsync() end) if(complete) then local head = plr.Character:FindFirstChild("Head") if head then print("HEAD") local over = head:FindFirstChild("PlayerOverhead") if over then local text = over.TextLabel text.Text = filteredText NameStore:SetAsync(plr.UserId, filteredText) end end end end end)
I do have the RemoteEvent and the BillboardGUI in ReplicatedStorage, and they are both correctly named. There are no errors in the Output and it is printing "HEAD" when the code finds the player's head. Thank you!
I have come up with my own solution. I moved the OnCharacterAdded part to a LocalScript in StarterCharacterScripts and changed it to a RemoteEvent function instead. Whenever the player would reset, it would fire a new RemoteEvent and the LocalScript would work. Thanks to anybody who considered helping!