How to give player said item after receiving amount of points

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)

Here’s the Leaderstats Script

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

Where do I put this?

Doesn’t work when I put it by itself in serverscriptservice

Here, replace your leaderstats with this :

Make sure you have a tool in ReplicatedStorage

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)
2 Likes

Thanks so much!!!

I’ll do it now

No problems, read the edited one, you forgot to parent the leaderstats and ‘time’ to the player

Big problem


Uhhh How do I fix that?

It’s because you didn’t parent the ‘leaderstats’ to the player

How would I do that?

Still new to scripting.

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)

It keeps giving the player the tool over and over

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)

Problem here xd

Thanks for your help btw

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)

Please send the Module that you’re using [in your Replicated Storage]

What if I want to do multiple given tools say

15 points you get this

10 points you get that

You can use if statements

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