I am making a gun that adds to your kills leaderstats when you get a kill but it gives me an error when i try to change the leaderstat and I do not know how to give a number to the kills leaderstats once the target is at 0 health
local deagle = script.Parent
deagle.Shoot.OnServerEvent:Connect(function(player,mousePos)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(deagle.Handle.Position,(mousePos - deagle.Handle.Position)*2147000,raycastParams)
deagle.Handle.GunShot:Play()
if raycastResult then
local hitPart = raycastResult.Instance
local model = hitPart:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Humanoid") then
model.Humanoid.Health -= 36
if model.Humanoid.Health == 0 then
player.leaderstats.Kills = player.leaderstats.Kills + 1
end
end
end
end
end)

1 comment
If your question has been answered please accept the answer that has been provided to you.