Greetings Developer, I’m Abd and I’m a Simple Scripter and I also Design UI’s sometimes!
I have a HandTo System Script with Points and I want to make the Points don’t reset when you leave the Game.
Can someone help me, please?
Script:
----------[LEADERSTATS]----------
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
local Points = Instance.new("StringValue")
Points.Name = "StaffPoints"
Points.Value = 0
Points.Parent = leaderstats
leaderstats.Parent = Player
if Player:GetRankInGroup(6419782) <= 3 then
Points.Value = "N/A"
end
end)
----------[SETTINGS]----------
local Settings = {
Prefix = ":",
Group = 6419782,
Rank = 4,
}
function GetWords(Msg,Pattern)
local Words = {}
for w in string.gmatch(Msg, Pattern) do
table.insert(Words,w)
end
return Words
end
local ChatFunctions = {
["handto"] = function(Words,Player)
for _,Target in pairs(game.Players:GetPlayers()) do
if string.find(string.lower(Target.Name),string.lower(Words[2])) then
local Tool = Player.Character:FindFirstChildOfClass("Tool")
local Human = Player.Character:FindFirstChildOfClass("Humanoid")
if Tool and Human then
Human:UnequipTools()
wait()
Tool.Parent = Target.Backpack
Player.leaderstats.StaffPoints.Value = Player.leaderstats.StaffPoints.Value + 1
end
end
wait()
end
end,
}
game.Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(Settings.Group) >= Settings.Rank then
Player.Chatted:Connect(function(Message)
if string.sub(Message,1,1) == Settings.Prefix then
local Command = GetWords(string.sub(Message,2),"[%w_]+")
if ChatFunctions[Command[1]] then
ChatFunctions[Command[1]](Command,Player)
end
end
end)
end
end)
local Data = game:GetService("DataStoreService"):GetDataStore("Name of your data store")
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
local Points = Instance.new("StringValue")
Points.Name = "StaffPoints"
Points.Value = 0
Points.Parent = leaderstats
leaderstats.Parent = Player
local PlayersData = Data:GetAsync(Player.UserId.."-HandToPoints")
if Player:GetRankInGroup(6419782) <= 3 and PlayersData == nil then
Points.Value = "N/A"
elseif Player:GetRankInGroup(6419782) >= 3 and PlayersData ~= nil then
Points.Value = PlayersData
end
end)
game.Players.PlayerRemoving:Connect(function(player)
Data:SetAsync(player.UserId.."-HandToPoints",player.leaderstats.StaffPoints.Value)
end)
----------[DATASTORE]----------
local Data = game:GetService("DataStoreService"):GetDataStore("Name of your data store")
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
local Points = Instance.new("StringValue")
Points.Name = "StaffPoints"
Points.Value = 0
Points.Parent = leaderstats
leaderstats.Parent = Player
local PlayersData = Data:GetAsync(Player.UserId.."-HandToPoints")
if Player:GetRankInGroup(6419782) <= 3 and PlayersData == nil then
Points.Value = "N/A"
elseif Player:GetRankInGroup(6419782) >= 3 and PlayersData ~= nil then
Points.Value = PlayersData
end
end)
game.Players.PlayerRemoving:Connect(function(player)
Data:SetAsync(player.UserId.."-HandToPoints",player.leaderstats.StaffPoints.Value)
end)
----------[LEADERSTATS]----------
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
local Points = Instance.new("StringValue")
Points.Name = "StaffPoints"
Points.Value = 0
Points.Parent = leaderstats
leaderstats.Parent = Player
if Player:GetRankInGroup(6419782) <= 3 then
Points.Value = "N/A"
end
end)
----------[SETTINGS]----------
local Settings = {
Prefix = ":",
Group = 6419782,
Rank = 4,
}
function GetWords(Msg,Pattern)
local Words = {}
for w in string.gmatch(Msg, Pattern) do
table.insert(Words,w)
end
return Words
end
local ChatFunctions = {
["handto"] = function(Words,Player)
for _,Target in pairs(game.Players:GetPlayers()) do
if string.find(string.lower(Target.Name),string.lower(Words[2])) then
local Tool = Player.Character:FindFirstChildOfClass("Tool")
local Human = Player.Character:FindFirstChildOfClass("Humanoid")
if Tool and Human then
Human:UnequipTools()
wait()
Tool.Parent = Target.Backpack
Player.leaderstats.StaffPoints.Value = Player.leaderstats.StaffPoints.Value + 1
end
end
wait()
end
end,
}
game.Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(Settings.Group) >= Settings.Rank then
Player.Chatted:Connect(function(Message)
if string.sub(Message,1,1) == Settings.Prefix then
local Command = GetWords(string.sub(Message,2),"[%w_]+")
if ChatFunctions[Command[1]] then
ChatFunctions[Command[1]](Command,Player)
end
end
end)
end
end)
Also, I am not an IDE. While I can quickly look over small scripts and possibly find bugs, you should test it in your game. Then come back here if it doesn’t work.