I'm trying to make it so when you click a button, it resets your stage and resets your datastore. I'm a beginner to remote events, so this is probably an easy fix.
Here is my code:
--code in the localscript local data = game:GetService("DataStoreService"):GetDataStore("Stage") local ReplicatedStorage = game:GetService("ReplicatedStorage") local resetDataEvent = ReplicatedStorage:WaitForChild("ResetDataEvent") script.Parent.MouseButton1Up:connect(function() game.ReplicatedStorage.ResetDataEvent:FireServer() end) --code in script local function resetData(plr) print("hi") plr.leaderstats.Stage.Value = 0 local key = "user_" .. game.Players.Localplayer.userId data:SetAsync(key, game.Players.Localplayer.leaderstats.Stage.Value) end game.ReplicatedStorage.ResetDataEvent.OnServerEvent:connect(resetData)
This code is basically ripped off the wiki. Please help!
in line 17-19 you said:
game.Players.Localplayer.leaderstats.Stage.Value = 0 local key = "user_" .. game.Players.Localplayer.userId data:SetAsync(key, game.Players.Localplayer.leaderstats.Stage.Value)
even though you set a parameter for player. the reason this doesn't work is because it doesn't know what player you are talking about. so because you set a parameter for player (plr) just say:
plr.leaderstats.Stage.Value = 0 local key = "user_" .. plr.userId data:SetAsync(key, plr.leaderstats.Stage.Value)
there might be other errors. im not sure, i didn't test it or do a thorough search, but accept this answer if it did work