You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I would like help and a script which detects when a player kills someone or the player dies, and adds one to the leaderstats.
What is the issue? Include enough details if possible!
I can’t figure out how to make it detect when a player dies and when they kill someone.
What solutions have you thought of so far?
I have tried seeing if humanoid health was less then 1 and if it was, it would add one to the deaths, but i dont know about the kills
All the leaderstats are done, and they are all being saved, I can also provide the script for the leaderstats if you need!
local datastore = game:GetService("DataStoreService"):GetDataStore("GameStore")
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local points = Instance.new("IntValue")
points.Name = "Level"
points.Parent = leaderstats
local wins = Instance.new("IntValue")
wins.Name = "Kills"
wins.Parent = leaderstats
local deaths = Instance.new("IntValue")
deaths.Name = "Deaths"
deaths.Parent = leaderstats
local key = "user-" .. player.userId
local storeditems = datastore:GetAsync(key)
if storeditems then
points.Value = storeditems[1]
wins.Value = storeditems[2]
deaths.Value = storeditems[3]
else
local items = {points.Value, wins.Value, deaths.Value}
datastore:SetAsync(key, items)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local items = {player.leaderstats.Points.Value, player.leaderstats.Wins.Value, player.leaderstats.Deaths.Value}
local key = "user-" .. player.userId
datastore:SetAsync(key, items)
end)
this is the datastore script
2 Likes
This might help with detecting when the player is dead:
https://developer.roblox.com/en-us/api-reference/event/Humanoid/Died
And this might help with adding a kill to the player’s stats:
Hello, devforum.
I’m confused on how i would detect if the player had killed an enemy.
Can someone help me please?
1 Like
Still doesn’t help me sorry. Could you explain a bit better on how to do it?
1 Like
I recommend researching more on DevForum, since you are not the first who asked about this.
Alright so, I shall give an explanation (And I’m on mobile so dear everything forgive me if the stuff I say isn’t formatted correctly)
A creator “value” is basically in simple terms, a Kill Check (Or detecting if there is a CreatorTag, then we can add a Kill stat to the player who defeated the target)
The way how the creator “value” is implemented, is that it’s basically a way of checking if a player’s Character (Aka the Humanoid) has been damaged or not
Take a look at this GIF her…
This will give you a wider point of view on what to do about which player died and who killed them!