Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do i reset a player's stats when they press "New game"?

Asked by 5 years ago
Edited 5 years ago

I basically want to create a button "New Game" and when they press it their stats get reset. I have the gui and in the gui i have the Script That fires an event named "ResetData" but i dont know what to put in the server script that makes the remote event reset the stats

DataStore

01local DataStoreService = game:GetService("DataStoreService")
02local DataStoreVersion = 10 -- Changing this version will wipe all data of players
03local DataStore = DataStoreService:GetDataStore("DataStorex"..DataStoreVersion) -- Changing "DataStoreV" will also wipe all data of players
04 
05game.Players.PlayerAdded:Connect(function(Player)
06    local Stats = Instance.new("Folder",Player)
07    Stats.Name = "Stats"
08 
09    local Strength = Instance.new("IntValue",Stats)
10    Strength.Name = "Strength"
11 
12    local Defense = Instance.new("IntValue",Stats)
13    Defense.Name = "Defense"
14 
15    local Energy = Instance.new("IntValue",Stats)
View all 63 lines...
0
Maybe set all Values to 0 and then possibly save them virushunter9 943 — 5y
0
Can we get an example of the code used to save the data? This will help. Void_Frost 571 — 5y
0
Ok, edited ItzSulfonic 61 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Maybe set all Values to 0 and then possibly save them

Ok i tried it but it doesnt save and it doesnt change energy and speed to 0 for some reason

1game.ReplicatedStorage.ResetData.OnServerEvent:Connect(function(clicked)
2    clicked.Stats.Strength.Value = 0
3    clicked.Stats.Defense.Value = 0
4    clicked.Stats.Energy.Value = 0
5    clicked.Stats.Speed.Value = 0
6    clicked.Stats.Rebirths.Value = 0
7end)
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Use a table. It's so much cleaner compared to using different keys. I've fixed your code:

01local DataStoreService = game:GetService("DataStoreService")
02local DataStoreVersion = 10 -- Changing this version will wipe all data of players
03local DataStore = DataStoreService:GetDataStore("DataStorex"..DataStoreVersion) -- Changing "DataStoreV" will also wipe all data of players
04 
05game.Players.PlayerAdded:Connect(function(Player)
06    local Stats = Instance.new("Folder",Player)
07    Stats.Name = "Stats"
08 
09    local Strength = Instance.new("IntValue",Stats)
10    Strength.Name = "Strength"
11 
12    local Defense = Instance.new("IntValue",Stats)
13    Defense.Name = "Defense"
14 
15    local Energy = Instance.new("IntValue",Stats)
View all 50 lines...

Also, since you said you were having trouble with tables, heres a very simple example:

1local value={
2TableValue1 = "test"
3}

if you type value.TableValue1 it will be "test"

0
its saying Expected '}' (to close '{' at line 43. got defense so i put ; after each line and that got rid of the red lines. Then when i tested it the stats did not save ItzSulfonic 61 — 5y
0
ah, i forgot commas. Please accept my answer :) Void_Frost 571 — 5y
0
The stats dont save tho ItzSulfonic 61 — 5y
0
Uh, that's your problem then, maybe because PlayerRemoving? My code is fine though... Any errors? Void_Frost 571 — 5y
View all comments (4 more)
0
no errors ItzSulfonic 61 — 5y
0
Can you add me on discord? Sulfonic#2593 ItzSulfonic 61 — 5y
0
Get rid of DataStoreVersion Void_Frost 571 — 5y
0
looks like there also needs to be an end) at line 41 Void_Frost 571 — 5y

Answer this question