I made this leaderstat script and it doesn’t seem to work. Any problems related? I am having SERIOUS issues with this.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Folder",plr)
ls.Name = "leaderstats"
local kills = Instance.new("IntValue",ls)
kills.Name = "Kills"
kills.Value = 0
local deaths = Instance.new("IntValue",ls)
deaths.Name = "Deaths"
deaths.Value = 0
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid") or Instance.new("Humanoid", char)
hum.Died:Connect(function()
deaths.Value+=1
local killtag = hum:FindFirstChild("creator")
if killtag and killtag.Value then
killtag.Value.leaderstats.Kills.Value+=1
end
end)
end)
end)
Do your swords/weapons have a function that create the creator tag?
Because that tag is NOT added automatically, you need to make a function inside your tools to make that tag
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
Here, this function could help you.
You might need to provide the humanoid and player accordingly to your adjustments.
local player = Players:GetPlayerFromCharacter(hit.Parent)
local debounce = false
if hit.Parent.Name ~= plr.Name and hit.Parent:FindFirstChild("Humanoid") and not debounce then
debounce = true
hit.Parent.Humanoid.Health -= dmg
projectile:Destroy()
if player then
local frame = player.PlayerGui.ScreenGui.WaterSplashFrame
frame.BackgroundTransparency = 0
local info = TweenInfo.new(2.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0,false,0)
local goals = {BackgroundTransparency = 1}
local tween = TweenService:Create(frame,info,goals)
tween:Play()
end
end
end)
and When ever the Player Clicks the sword it would make hitted to true and you would check if hitted is true And making a touching Event if the Player HumanoidRootPart was Touched with hitted being true it would damage the Player and if that Player died the Player gets 1 more kill.