I have this in a local script:
ReplicatedStorage:WaitForChild("ChangeParam"):FireServer(game.Players.LocalPlayer.data.has_done_intro.Value, true)
and this in the server script:
ReplicatedStorage.ChangeParam.OnServerEvent:Connect(function(player, param, new) param = new save_data(player) end) -- save_data(player) just saves the datastore.
I suppose this code doesn't work because the change is done in the local script, and not the server script (where it should be done in order for save_data to work). My goal is to be able to change the user's variables (in the folder leaderstats and a folder I created called data) from any local script, without having to make separate remote events for every single thing I want to change. Is there a way to do that? Maybe I should stick to separate remote events for each parameter (such as changing coins, level...)?
Hello KamptonGames! To do this, you will need to fire a remote event with what you want to be changed and the new value! Let's get started:
SETUP
1) Create a remote event under replicated storage
-Name the event "ChangeData"
2) Make a server script under ServerScriptService
-Name it "DataMain"
3) Make a local script and put it wherever you need to fire the dataChange
-Name it at your discretion
SCRIPTING
In the DataMain Server script:
ChangeEV = game:GetService("ReplicatedStorage"):WaitForChild("ChangeData") ChangeEV.OnServerEvent:Connect(function(plr, dataName, dataValue) local toChange = plr.leaderstats:FindFirstChild(dataName) toChange.Value = dataValue end)
In the local script, you can put this line of code whenever you want to change data:
game:GetService("ReplicatedStorage"):WaitForChild("ChangeData"):FireServer(*name of data here*, *new value for data here*)
With that said, of course the data name would actually have to exist in leaderstats, and the new value should equal the data type. But I hope this helped! With any further questions/comments/concerns, please feel free to comment on my answer! ~mc3334