I have a Notepad GUI in my game and I want to save the notepad’s text when the player leaves and load the notepad’s saved text when the player join’s back but for some reason my code won’t work and there’s no error’s that show inside of the console. Even using online tutorial’s and stuff also won’t work so here I am lol.
Server Script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local NotepadData = DataStoreService:GetDataStore("NotepadData")
Players.PlayerAdded:Connect(function(Player)
local Data
local Success, Error = pcall(function()
Data = NotepadData:GetAsync("User_"..Player.UserId)
end)
if Success and Data then
ReplicatedStorage.Events.RemoteEvents.NotepadChangedText:FireClient(Player, Data)
end
end)
ReplicatedStorage.Events.RemoteEvents.NotepadSaveText.OnServerEvent:Connect(function(Player, Text)
pcall(function()
NotepadData:SetAsync("User_"..Player.UserId, Text)
end)
end)
LocalScript that controls the Notepad (some lines have been cut out in this post only):
ReplicatedStorage.Events.RemoteEvents.NotepadChangedText.OnClientEvent:Connect(function(Text)
TextBox.Text = Text
end)
game.Players.PlayerRemoving:Connect(function(Player)
if Player == game.Players.LocalPlayer then
ReplicatedStorage.Events.RemoteEvents.NotepadSaveText:FireServer(TextBox.Text)
end
end)
spawn(function()
while wait(60) do --my attempt at an auto save
ReplicatedStorage.Events.RemoteEvents.NotepadSaveText:FireServer(TextBox.Text)
end
end)