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)
player.leaderstats.Kills is the object that you can see in the explorer, but the actual number that's stored inside of the object is in the "Value" property. The script gives an error because you're trying to add to "player.leaderstats.Kills", but it fails because that is an instance and not a number. In the line that changes the amount of kills, do this instead:
player.leaderstats.Kills.Value = player.leaderstats.Kills.Value + 1