I've been trying to do this all day but I can't figure it out, does anybody know how I can get it working?
I have a script in the Menu of the game and another in the main game.
Script 1:
local ds = game:GetService("DataStoreService"):GetDataStore("PlayerName")
game.Players.PlayerRemoving:Connect(function(plr)
local f = Instance.new("Folder")
f.Name = "leaderstats"
f.Parent = plr
local nameVal = Instance.new("StringValue")
nameVal.Name = "NameValue"
nameVal.Parent = f
nameVal.Value = plr.PlayerGui.ScreenGui.Frame.TextBox.Text
game.Players.PlayerRemoving:Connect(function(player)
if player.UserId == plr.UserId then
ds:SetAsync(player.UserId, player.leaderstats.NameValue.Value)
end
end)
end)
Script 2:
local ds = game:GetService("DataStoreService"):GetDataStore("PlayerName")
local data
game.Players.PlayerAdded:Connect(function(plr)
local f = Instance.new("Folder")
f.Name = "leaderstats"
f.Parent = plr
local nameVal = Instance.new("StringValue")
nameVal.Name = "NameValue"
nameVal.Parent = f
data = ds:GetAsync(plr.UserId)
plr.leaderstats.NameValue.Value = data
end)

1 comment
I fixed it by using teleport data instead of using datastores