Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is error given when trying to add to kills leaderstat?

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

0

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

1 answer

✓ Accepted answer

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

1 comment

0

oh lol, thanks. I can't believe i missed that mistake lol

This discussion is preserved as it was. New answers, comments, and votes are closed.