Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Jec0be 11
3 years ago

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)
0
If your question has been answered please accept the answer that has been provided to you. AntoninFearless 622 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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
0
oh lol, thanks. I can't believe i missed that mistake lol Jec0be 11 — 3y
Ad

Answer this question