Heya! Was wondering how to give a player an item when they reach a said amount of points
local DSS = require(game.ServerStorage.Modules.Datastores)
function onPlayerEntered(newPlayer)
local PlrStore = DSS:GetStore(newPlayer, "StatsStore", {})
--Blank table cuz we don't have a path
if not PlrStore then
repeat
PlrStore = DSS:GetStore(newPlayer, "StatsStore", {})
wait(0.25)
until PlrStore
end
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local score = Instance.new("IntValue")
score.Name = "Time"
score.Value = PlrStore.Time
newPlayer.CharacterAdded:Connect(function(char)
print("CharAdded")
local BillboardGui = game.ServerStorage.ClonedObjects.Example:Clone()
BillboardGui.Parent = char.Head
BillboardGui.Name = "Time"
BillboardGui.Time.Text = score.Value
end)
score.Parent = stats
stats.Parent = newPlayer
local function onValChanged(value)
--This is just for backwards compatibility because normally you would want to change the player stores then update leaderstats--
--but it wasn't like that so this updates the stats--
DSS:ChangeStore(newPlayer, "StatsStore", {value.Name}, value.Value)
end
score:GetPropertyChangedSignal("Value"):Connect(function()
onValChanged(score)
if newPlayer.Character then
if not newPlayer.Character.Head:FindFirstChild("Time") then
local BillboardGui = game.ServerStorage.ClonedObjects.Example:Clone()
BillboardGui.Parent = newPlayer.Character.Head
BillboardGui.Name = "Time"
BillboardGui.Time.Text = score.Value
end
newPlayer.Character.Head.Time.Time.Text = score.Value
end
end)
while true do
wait(0.85)
if not newPlayer.Character then return end
if not table.find(workspace:FindPartsInRegion3WithWhiteList(_G.SafeZone, {newPlayer.Character}), newPlayer.Character.HumanoidRootPart) then
newPlayer.leaderstats.Time.Value = newPlayer.leaderstats.Time.Value +1
end
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
newPlayer.leaderstats.Points.Changed:connect(function()
if newPlayer.leaderstats.Points.Value >= 100 then
local tool = game.ReplicatedStorage.Tool:clone()
tool.Parent = newPlayer.Backpack
end
end)
This is a basic script to detect when the stats have changed, and we then check what is their value,
if it’s higher than/ equal to 100 [up to your choice], then we clone a tool and parent it to Player’s backpack.
Make sure that player hasn’t got that tool already, otherwise he’ll keep receiving this tool
local DSS = require(game.ServerStorage.Modules.Datastores)
function onPlayerEntered(newPlayer)
local PlrStore = DSS:GetStore(newPlayer, "StatsStore", {})
--Blank table cuz we don't have a path
if not PlrStore then
repeat
PlrStore = DSS:GetStore(newPlayer, "StatsStore", {})
task.wait(0.25)
until PlrStore
end
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
stats.Parent = newPlayer
local score = Instance.new("IntValue",stats)
score.Name = "Time"
score.Value = PlrStore.Time
newPlayer.leaderstats.Time.Changed:connect(function()
if newPlayer.leaderstats.Time.Value >= 100 then
local tool = game.ReplicatedStorage.Tool:clone()
tool.Parent = newPlayer.Backpack
end
end)
newPlayer.CharacterAdded:Connect(function(char)
print("CharAdded")
local BillboardGui = game.ServerStorage.ClonedObjects.Example:Clone()
BillboardGui.Parent = char.Head
BillboardGui.Name = "Time"
BillboardGui.Time.Text = score.Value
end)
score.Parent = stats
stats.Parent = newPlayer
local function onValChanged(value)
--This is just for backwards compatibility because normally you would want to change the player stores then update leaderstats--
--but it wasn't like that so this updates the stats--
DSS:ChangeStore(newPlayer, "StatsStore", {value.Name}, value.Value)
end
score:GetPropertyChangedSignal("Value"):Connect(function()
onValChanged(score)
if newPlayer.Character then
if not newPlayer.Character.Head:FindFirstChild("Time") then
local BillboardGui = game.ServerStorage.ClonedObjects.Example:Clone()
BillboardGui.Parent = newPlayer.Character.Head
BillboardGui.Name = "Time"
BillboardGui.Time.Text = score.Value
end
newPlayer.Character.Head.Time.Time.Text = score.Value
end
end)
while true do
task.wait(0.85)
if not newPlayer.Character then return end
if not table.find(workspace:FindPartsInRegion3WithWhiteList(_G.SafeZone, {newPlayer.Character}), newPlayer.Character.HumanoidRootPart) then
newPlayer.leaderstats.Time.Value = newPlayer.leaderstats.Time.Value +1
end
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
local DSS = require(game.ServerStorage.Modules.Datastores)
function onPlayerEntered(newPlayer)
local PlrStore = DSS:GetStore(newPlayer, "StatsStore", {})
--Blank table cuz we don't have a path
if not PlrStore then
repeat
PlrStore = DSS:GetStore(newPlayer, "StatsStore", {})
task.wait(0.25)
until PlrStore
end
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
stats.Parent = newPlayer
local score = Instance.new("IntValue",stats)
score.Name = "Time"
score.Value = PlrStore.Time
newPlayer.leaderstats.Time.Changed:connect(function()
if newPlayer.leaderstats.Time.Value >= 100 then
local tool = game.ReplicatedStorage.Tool:clone()
tool.Parent = newPlayer.Backpack
end
end)
newPlayer.CharacterAdded:Connect(function(char)
print("CharAdded")
local BillboardGui = game.ServerStorage.ClonedObjects.Example:Clone()
BillboardGui.Parent = char.Head
BillboardGui.Name = "Time"
BillboardGui.Time.Text = score.Value
end)
score.Parent = stats
stats.Parent = newPlayer
local function onValChanged(value)
--This is just for backwards compatibility because normally you would want to change the player stores then update leaderstats--
--but it wasn't like that so this updates the stats--
DSS:ChangeStore(newPlayer, "StatsStore", {value.Name}, value.Value)
end
score:GetPropertyChangedSignal("Value"):Connect(function()
onValChanged(score)
if newPlayer.Character then
if not newPlayer.Character.Head:FindFirstChild("Time") then
local BillboardGui = game.ServerStorage.ClonedObjects.Example:Clone()
BillboardGui.Parent = newPlayer.Character.Head
BillboardGui.Name = "Time"
BillboardGui.Time.Text = score.Value
end
newPlayer.Character.Head.Time.Time.Text = score.Value
end
end)
while true do
task.wait(0.85)
if not newPlayer.Character then return end
if not table.find(workspace:FindPartsInRegion3WithWhiteList(_G.SafeZone, {newPlayer.Character}), newPlayer.Character.HumanoidRootPart) then
newPlayer.leaderstats.Time.Value = newPlayer.leaderstats.Time.Value +1
end
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
local DSS = require(game.ServerStorage.Modules.Datastores)
function onPlayerEntered(newPlayer)
local PlrStore = DSS:GetStore(newPlayer, "StatsStore", {})
--Blank table cuz we don't have a path
if not PlrStore then
repeat
PlrStore = DSS:GetStore(newPlayer, "StatsStore", {})
task.wait(0.25)
until PlrStore
end
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
stats.Parent = newPlayer
local score = Instance.new("IntValue",stats)
score.Name = "Time"
score.Value = PlrStore.Time
newPlayer.leaderstats.Time.Changed:connect(function()
if newPlayer.leaderstats.Time.Value >= 100 then
local tool = game.ReplicatedStorage.Tool:clone()
if not newPlayer.Backpack:FindFirstChild(tool.Name) then tool.Parent = newPlayer.Backpack end
end)
newPlayer.CharacterAdded:Connect(function(char)
print("CharAdded")
local BillboardGui = game.ServerStorage.ClonedObjects.Example:Clone()
BillboardGui.Parent = char.Head
BillboardGui.Name = "Time"
BillboardGui.Time.Text = score.Value
end)
score.Parent = stats
stats.Parent = newPlayer
local function onValChanged(value)
--This is just for backwards compatibility because normally you would want to change the player stores then update leaderstats--
--but it wasn't like that so this updates the stats--
DSS:ChangeStore(newPlayer, "StatsStore", {value.Name}, value.Value)
end
score:GetPropertyChangedSignal("Value"):Connect(function()
onValChanged(score)
if newPlayer.Character then
if not newPlayer.Character.Head:FindFirstChild("Time") then
local BillboardGui = game.ServerStorage.ClonedObjects.Example:Clone()
BillboardGui.Parent = newPlayer.Character.Head
BillboardGui.Name = "Time"
BillboardGui.Time.Text = score.Value
end
newPlayer.Character.Head.Time.Time.Text = score.Value
end
end)
while true do
task.wait(0.85)
if not newPlayer.Character then return end
if not table.find(workspace:FindPartsInRegion3WithWhiteList(_G.SafeZone, {newPlayer.Character}), newPlayer.Character.HumanoidRootPart) then
newPlayer.leaderstats.Time.Value = newPlayer.leaderstats.Time.Value +1
end
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
local DSS = require(game.ServerStorage.Modules.Datastores)
function onPlayerEntered(newPlayer)
local PlrStore = DSS:GetStore(newPlayer, "StatsStore", {})
--Blank table cuz we don't have a path
if not PlrStore then
repeat
PlrStore = DSS:GetStore(newPlayer, "StatsStore", {})
task.wait(0.25)
until PlrStore
end
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = newPlayer
local score = Instance.new("IntValue",stats)
score.Name = "Time"
score.Value = PlrStore.Time
newPlayer.leaderstats.Time.Changed:connect(function()
if newPlayer.leaderstats.Time.Value >= 100 then
local tool = game.ReplicatedStorage.Tool
if not newPlayer.Backpack:FindFirstChild(tool.Name) then
local clone = tool:Clone()
clone.Parent = newPlayer.Backpack
end
end
end)
newPlayer.CharacterAdded:Connect(function(char)
print("CharAdded")
local BillboardGui = game.ServerStorage.ClonedObjects.Example:Clone()
BillboardGui.Parent = char.Head
BillboardGui.Name = "Time"
BillboardGui.Time.Text = score.Value
end)
score.Parent = stats
stats.Parent = newPlayer
local function onValChanged(value)
--This is just for backwards compatibility because normally you would want to change the player stores then update leaderstats--
--but it wasn't like that so this updates the stats--
DSS:ChangeStore(newPlayer, "StatsStore", {value.Name}, value.Value)
end
score:GetPropertyChangedSignal("Value"):Connect(function()
onValChanged(score)
if newPlayer.Character then
if not newPlayer.Character.Head:FindFirstChild("Time") then
local BillboardGui = game.ServerStorage.ClonedObjects.Example:Clone()
BillboardGui.Parent = newPlayer.Character.Head
BillboardGui.Name = "Time"
BillboardGui.Time.Text = score.Value
end
newPlayer.Character.Head.Time.Time.Text = score.Value
end
end)
while true do
task.wait(0.85)
if not newPlayer.Character then return end
if not table.find(workspace:FindPartsInRegion3WithWhiteList(_G.SafeZone, {newPlayer.Character}), newPlayer.Character.HumanoidRootPart) then
newPlayer:WaitForChild("leaderstats").Time.Value += 1
end
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
if newPlayer.leaderstats.Time.Value == 10 then
local tool = game.ReplicatedStorage.YourToolName
if not newPlayer.Backpack:FindFirstChild(tool.Name) then
end
elseif newPlayer.leaderstats.Time.Value == 15 then
local tool = game.ReplicatedStorage.YourToolName
if not newPlayer.Backpack:FindFirstChild(tool.Name) then
end
end