Hey,
I’ve been trying to send a textbox text through a datastore so that when the player joins back into the game it loads the same text they typed in before they left.
I haven’t been able to figure out why its not loading the data and I’ve been searching for a while but could not find why.
Server Script:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TextSave")
local SaveEvent = game.ReplicatedStorage.Remotes.ControlSave
SaveEvent.OnServerEvent:Connect(function(localPlayer, SaveData)
local success,errormessage = pcall(function()
local Key = localPlayer.UserId
DataStore:SetAsync(Key, SaveData)
print("Set Async")
end)
while not success do
local Key = localPlayer.UserId
print("Trying To Set Async")
DataStore:SetAsync(Key, SaveData)
print("Set Async")
wait(3)
end
end)
game.Players.PlayerAdded:Connect(function(localPlayer, SaveData)
local Key = localPlayer.UserId
local success, errormessage = pcall(function()
local Data = DataStore:GetAsync(Key)
if Data then
SaveData = Data[1]
print(SaveData)
end
end)
while not success do
local Data = DataStore:GetAsync(Key)
print("Working On it")
if Data then
SaveData = Data[1]
print(SaveData)
wait(2)
end
end
end)
Local Script:
local TextBox = script.Parent
local SaveEvent = game.ReplicatedStorage.Remotes.ControlSave
local function OnTextBoxFocusLost(EnterPressed, InputObject)
if EnterPressed then
print("Pressed Enter")
local SaveData = TextBox.Text
SaveEvent:FireServer(SaveData)
print("Saved")
end
end
TextBox.FocusLost:Connect(OnTextBoxFocusLost)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.