How to save changes made by a local script when player leaves game

So i have a local script that makes it so when you touch a part it changes the proprieties of another part (like color and material for example) on their screen. How do i make it so when the player leaves the game those proprieties changes remain when they rejoin.

I recommend using DataStores, then when the player rejoins send all the saved data to the client to make the appropriate changes

1 Like

Can you go more in depth, im not too familiar with DataStores

Absolutely!

So on both the server and client side these would be something similar to the script you would use

Server Script:

local DS = game:GetService("DataStoreService")
local Data = DS:GetDataStore("WhateverYouWantYourDataStoreToBeCalled")

local TransferDataRemote = game.ReplicatedStorage.RemoteEvent

game.Players.PlayerAdded:Connect(function(player)
local PlayerData = Data:GetASync(player.UserId.."-clientData")

if PlayerData ~= nil then -- if the player doesn't have any existing data
TransferDataRemote:FireClient(PlayerData)
end
end)

TransferDataRemote.OnServerEvent:Connect(function(player, Data)
Data:SetAsync(player.UserId.."-clientData",Data)
end)

Local Script:

local TransferDataRemote = game.ReplicatedStorage.RemoteEvent
TransferDataRemote.OnClientEvent:Connect(function(Data)
part.Color = Data
end)

part.Changed:Connect(function()
TransferDataRemote:FireServer(part.Color)
end)
3 Likes