Give points for hit players

how do I make it give me one point for 1 hit and between 7 and 10 points for each kill?
and how do I show the points both on the gui and on the leaderboard?

local Players = game:GetService("Players")

local function onPlayerAdded(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local points = Instance.new("IntValue")
	points.Name = "Points"
	points.Value = 0
	points.Parent = leaderstats
	
	local Ability = Instance.new("StringValue")
	Ability.Name = "Ability"
	Ability.Value = "Human"
	Ability.Parent = leaderstats
end

Players.PlayerAdded:Connect(onPlayerAdded)

You want to make a point system for each kill and hit?
You may use The Basic Simple Touched Event to detect the player and reward a point.But if you use something that uses Raycast then you should be able to detect with it too.İf a player is detected then you have to set a new value as:

local NewValue = CurrentValue + ValueToAdd --added the required value to current value and made it variable to use it.

You want to show the points on leaderboard and gui.To do them you just need to access Player’s leaderstats folder and the Gui.You have to update them with the new value of points.

local NewValue = CurrentValue + ValueToAdd --added the required value to current value and made it variable to use it.

Game.Players:GetPlayerFromCharacter(Hit.Parent).leaderstats.Points.Value = NewValue

Caution⚠️
Using IntValue to make a number variable is not true and not recommended.Using the NumberValue is the best way to do it.

There’s still a way to do it with IntValue.

IntValue

local NewValue = tonumber(CurrentValue) + ValueToAdd --added the required value to current value and made it variable to use it.

Game.Players:GetPlayerFromCharacter(Hit.Parent).leaderstats.Points.Value = NewValue

NumberValue

local NewValue = CurrentValue + ValueToAdd --added the required value to current value and made it variable to use it.

Game.Players:GetPlayerFromCharacter(Hit.Parent).leaderstats.Points.Value = NewValue
2 Likes

can you give me an example of code that I can follow and modify according to my needs?

Sure! i can give you some basic examples to do your goal!

How can i update player’s point in leaderboard?

Player = game.Players.LocalPlayer
CurrentValue = Player.leaderstats.Points.Value

NewValue = CurrentValue + math.random(7,10) --For an example

CurrentValue = NewValue

How can i update player’s point in gui?

Player = game.Players.LocalPlayer
CurrentValue = Player.PlayerGui.Stats.StatsFrame.Points.Text

NewValue = tonumber(CurrentValue) + math.random(7,10) --For an example

CurrentValue = tostring(NewValue) --You just can write a number to a text i used the tostring command for this time.

Do you need something more? Tell me and i’ll help!

Caution⚠️: If you want this things to update everytime.Then you have to use loops to update.