Hello, so I have been trying to a datastore that saves The Letters/numbers the player last left in a GUI for example this photo here
I want to make the letters or numbers in the GUI same as the player last left it but I am getting really confused
So if I understand this correctly, you basically just want to change the text into whatever the player’s last input was.
In order to do this, you just need to edit the .Text
property in your GUI object.
Example
yourGui.Text = savedData
Anything you want to store for long term use needs to be in a DataStore.
This should be used in the script that recieves your datastore information (which is most likely a local script).
How I would do this is by getting the text of the TextLabel, then saving it in the datastore as a key, something like this:
local TextToSave = "You have obtained a new car!"
DataStore["SavedText"] = TextToSave
Then after then player rejoins the game, you would send a remote event and set the text of a TextLabel to the saved text in the datastore
Would look something like this:
local Text = DataStore:GetAsync("key")
RemoteEvent:FireClient(PlayerThatJoinedServer, Text)
Well how are you currently sending data?
Thanks for responding but I am really bad when it comes to datastores I want to know how i can do it
I don’t know I’m using datastore service to save data I guess
Here I just make a quick datastore for you that works.
local Data = game:GetService("DataStoreService")
local PlayerDataStore = Data:GetDataStore("PlayerData")
local function PlayerAdded(Player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = Player
leaderstats.Name = "leaderstats"
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Value = 0
Coins.Parent = leaderstats
local SavedData = nil
local success, err = pcall(function()
SavedData = PlayerDataStore:GetAsync("Player-"..Player.UserId)
end)
if SavedData then
Coins.Value = SavedData["Coins"]
else
Coins.Value = 0
end
Coins.Value += 1
end
local function DataTable(Player)
local t = {}
for i,v in ipairs(Player.leaderstats:GetChildren()) do
t[v.Name] = v.Value
end
return t
end
local function PlayerRemoved(Player)
local DataTable = DataTable(Player)
local success, err = pcall(function()
PlayerDataStore:SetAsync("Player-"..Player.UserId, DataTable)
end)
if err then
warn(err)
end
end
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoved)
I think it would be best to use this as reference to making datastores in the future for your self.
Thanks I really appreciate everything I just haven’t scripted in 2 years and have gotten a little bad at it
I can understand the script but the problem is everything has changed since i last scripted i just got back to scripting like 2 months ago
Oh you will need to use datastores and remote events. In localscripts you can’t really use datastores.
The GUI is about second layer minecraft skin this is the script I use in ServerScriptService maybe i could just save the id in the scirpt or something here’s the script:local ReplicatedStorage = game:GetService(‘ReplicatedStorage’)
local SkinRemote = ReplicatedStorage.SkinRemote
SkinRemote.OnServerEvent:Connect(function(player, mode, id)
local character = player.Character
if mode == "skin" then
for _, part in pairs(character:GetDescendants()) do
if part:IsA("MeshPart") then
part.TextureID = id
end
end
elseif mode == "layers" then
local transparency = id and 0.001 or 1
for _, part in pairs(character.SecondLayer:GetChildren()) do
part.Transparency = transparency
end
end
end)
You can do this as with leaderstats, it’s actually pretty easy. You will have to save the text the player last typed, store it and when the player joins, check if there’s any saved text, if it is, just fire a RemoteEvent to change the text locally. This can be exploited, but doesn’t really matter cause it could only perjudicate local experience. Here’s an example:
-- LocalScript
local RS = game:GetService("ReplicatedStorage")
local TextBox = script.Parent:WaitForChild("TextBox")
RS.ChangeText.OnClientEvent:Connect(function(text)
TextBox.Text = text
end)
TextBox:GetPropertyChangedSignal("Text"):Connect(function()
RS.SaveText:FireServer(TextBox.Text)
end)
-- Server
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local DSS = game:GetService("DataStoreService")
local TextBoxData = DSS:GetDataStore("TextBoxData")
Players.PlayerAdded:Connect(function(client)
local Data
local Success, Error = pcall(function()
Data = TextBoxData:GetAsync(client.UserId)
end)
if Success and Data then
RS.ChangeText:FireClient(client, Data) -- Localize the textbox with your own path
end
end)
RS.SaveText.OnServerEvent:Connect(function(client, text)
pcall(function()
TextBoxData:SetAsync(client.UserId, text)
end)
end)
Don’t try using RemoteFunctions or PlayerRemoving events, this will fail since remotes can’t be send when player has left, if you get data from server it will not see any changes made by the client like the TextBox’s text.
But i don’t want leaderboards i just want for example the last id typed in to be saved so that the payer doesn’t have to type it in manually
I’m not saving leaderboars/leaderstats (?) As you said, this is an example of saving TextBox’s last text (last text the player writed).
Okay thanks il try this and tell you if it works
Server scripts do not run on ServerStorage, there’s also minimum differences of inserting it on ServerScriptService than other services like Workspace, mostly just organization.
on the client do
game.Players.PlayerRemoving:Connect(function(Player)
if Player == game.Players.LocalPlayer then
–Fire a remote with the value in the ui
end
end)
PlayerRemoving fires before the Player instance gets destroyed so you will be able to access the gui