so i made a gui with a reset button, and i want to make that if player has right amount of gold and level then everytime player presses this button it will set their GOLD,LOVE,EXP to 0, and add 1 Reset
here’s my datastore2 script:
--variables
local DataStore2 = require(game:GetService("ServerScriptService").MainModule)
local mainkey = "as"
DataStore2.Combine(mainkey, "Stats","SOULS","ITEMS","FOOD","ARMOR")
-- data table
local function SetDataTable()
local UserData = {
Stats = {
["EXP"] = 0,
["GOLD"] = 0,
["RESET"] = 0,
["LOVE"] = 1
},
SOULS = {
["BasicSoul"] = true,
["Determination"] = false,
["Integrity"] = false,
["Justice"] = false,
["Perseverance"] = false,
["Kindness"] = false,
["Bravery"] = false,
["Patience"] = false
},
ITEMS = {
["Stick"] = true,
["REALKnife"] = false
},
ARMOR = {
["Bandage"] = true,
["HeartLocket"] = false
},
FOOD = {
["MonsterCandy"] = 0,
},
}
return UserData
end
--main
game.Players.PlayerAdded:Connect(function(plr)
local UserData = DataStore2(mainkey,plr):Get(SetDataTable())
local gaster = Instance.new("Folder")
gaster.Name = "TobyFox"
local soulsfolder = Instance.new("Folder")
soulsfolder.Name = "SOULS"
local ITEMS = Instance.new("Folder")
ITEMS.Name = "ITEMS"
local ARMOR = Instance.new("Folder")
ARMOR.Name = "ARMOR"
local FOOD = Instance.new("Folder")
FOOD.Name = "FOOD"
--userStats
local LOVE = Instance.new("IntValue")
LOVE.Name = "LOVE"
local GOLD = Instance.new("IntValue")
GOLD.Name = "GOLD"
local RESET = Instance.new("IntValue")
RESET.Name = "RESET"
local EXP = Instance.new("IntValue")
EXP.Name = "EXP"
--souls
local BasicSoul = Instance.new("BoolValue")
BasicSoul.Name = "BasicSoul"
local Determination = Instance.new("BoolValue")
Determination.Name = "Determination"
local Justice = Instance.new("BoolValue")
Justice.Name = "Justice"
local Integrity = Instance.new("BoolValue")
Integrity.Name = "Integrity"
local Bravery = Instance.new("BoolValue")
Bravery.Name = "Bravery"
local Kindness = Instance.new("BoolValue")
Kindness.Name = "Kindness"
local Patience = Instance.new("BoolValue")
Patience.Name = "Patience"
local Perseverance = Instance.new("BoolValue")
Perseverance.Name = "Perseverance"
--items
local Stick = Instance.new("BoolValue")
Stick.Name = "Stick"
local REALKnife = Instance.new("BoolValue")
REALKnife.Name = "REALKnife"
--Armor
local Bandage = Instance.new("BoolValue")
Bandage.Name = "Bandage"
local HeartLocket = Instance.new("BoolValue")
HeartLocket.Name = "HeartLocket"
--Food
local MonsterCandy = Instance.new("IntValue")
MonsterCandy.Name = "MonsterCandy"
--StoreInFolder
StatsData = DataStore2("Stats", plr)
local SoulsData = DataStore2("SOULS", plr)
local ItemsData = DataStore2("ITEMS",plr)
local FoodData = DataStore2("FOOD", plr)
local ArmorData = DataStore2("ARMOR", plr)
--Stats data
local function UpdateStats(UpdateValue) -- updates value to current data
LOVE.Value = StatsData:Get(UpdateValue).LOVE
EXP.Value = StatsData:Get(UpdateValue).EXP
GOLD.Value = StatsData:Get(UpdateValue).GOLD
RESET.Value = StatsData:Get(UpdateValue).RESET
end
--Soul data
local function UpdateSouls(UpdateValue)
BasicSoul.Value = SoulsData:Get(UpdateValue).BasicSoul
Determination.Value = SoulsData:Get(UpdateValue).Determination
Perseverance.Value = SoulsData:Get(UpdateValue).Perseverance
Patience.Value = SoulsData:Get(UpdateValue).Patience
Kindness.Value = SoulsData:Get(UpdateValue).Kindness
Bravery.Value = SoulsData:Get(UpdateValue).Bravery
Justice.Value = SoulsData:Get(UpdateValue).Justice
Integrity.Value = SoulsData:Get(UpdateValue).Integrity
end
--update data
UpdateStats(UserData.Stats)
UpdateSouls(UserData.SOULS)
StatsData:OnUpdate(UpdateStats)
SoulsData:OnUpdate(UpdateSouls)
--parent
gaster.Parent = plr
soulsfolder.Parent = plr
--allinonestats
--stats
LOVE.Parent = gaster
RESET.Parent = gaster
EXP.Parent = gaster
GOLD.Parent = gaster
--Souls
Determination.Parent = soulsfolder
BasicSoul.Parent = soulsfolder
Perseverance.Parent = soulsfolder
Integrity.Parent = soulsfolder
Justice.Parent = soulsfolder
Kindness.Parent = soulsfolder
Bravery.Parent = soulsfolder
Patience.Parent = soulsfolder
--LEVE SYSTEN start
EXP.Changed:connect(function()
if UserData.Stats.LOVE < 100 then
if UserData.Stats.EXP >= UserData.Stats.LOVE*25 + 10 then
UserData.Stats.EXP = UserData.Stats.EXP - (UserData.Stats.LOVE*25 + 10)
UserData.Stats.LOVE = UserData.Stats.LOVE + 1
StatsData:Set(UserData.Stats)
end
end
end)
LOVE.Changed:connect(function()
if UserData.Stats.LOVE >= 100 then
UserData.Stats.LOVE = 100
StatsData:Set(UserData.Stats)
end
end)
end)
workspace.yesname.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
local UserData = DataStore2(mainkey,PlayerWhoClicked):Get(SetDataTable())
local StatsData = DataStore2("Stats", PlayerWhoClicked)
local EXP = PlayerWhoClicked.TobyFox.EXP
local LOVE = PlayerWhoClicked.TobyFox.LOVE
if UserData.Stats.LOVE < 100 then
UserData.Stats.EXP = UserData.Stats.EXP + 2000
StatsData:Set(UserData.Stats)
if UserData.Stats.EXP >= UserData.Stats.LOVE*25 + 10 then
UserData.Stats.EXP = UserData.Stats.EXP - (UserData.Stats.LOVE*25 + 10)
UserData.Stats.LOVE = UserData.Stats.LOVE + 1
StatsData:Set(UserData.Stats)
end
end
end)
workspace.goldname.ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
local UserData = DataStore2(mainkey,PlayerWhoClicked):Get(SetDataTable())
local StatsData = DataStore2("Stats", PlayerWhoClicked)
UserData.Stats.GOLD = UserData.Stats.GOLD + 100000
StatsData:Set(UserData.Stats)
end)