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
01 | local deagle = script.Parent |
02 |
03 | deagle.Shoot.OnServerEvent:Connect( function (player,mousePos) |
04 | local raycastParams = RaycastParams.new() |
05 | raycastParams.FilterDescendantsInstances = { player.Character } |
06 | raycastParams.FilterType = Enum.RaycastFilterType.Blacklist |
07 |
08 |
09 | local raycastResult = workspace:Raycast(deagle.Handle.Position,(mousePos - deagle.Handle.Position)* 2147000 ,raycastParams) |
10 |
11 | deagle.Handle.GunShot:Play() |
12 | if raycastResult then |
13 | local hitPart = raycastResult.Instance |
14 | local model = hitPart:FindFirstAncestorOfClass( "Model" ) |
15 |
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:
1 | player.leaderstats.Kills.Value = player.leaderstats.Kills.Value + 1 |