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

Kill Reward System Not Working Properly?

Asked by 6 years ago

Server Script:

local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local plr = game.Players:GetPlayerFromCharacter(char)
local plrstats = plr:WaitForChild("leaderstats")
local plrcurrentkills = plrstats:WaitForChild("Current Kills") 

hum.Died:Connect(function()
    plrcurrentkills.Value = 0
    for i,v in pairs(char:GetChildren()) do
        if v:IsA("IntValue") then
            local newplr = game.Players:FindFirstChild(v.Name) --clearly defines what "newplr" is
            local newplrstats = newplr:FindFirstChild("leaderstats") --error occurs here saying that newplr is nil
            local newplrcurrentkills = newplrstats:FindFirstChild("Current Kills")
            local newplrkills = newplrstats:FindFirstChild("Kills")
            newplrkills.Value = newplrkills.Value + 1
            newplrcurrentkills.Value = newplrcurrentkills.Value + 1
        end
    end
end)

The script is placed in the StarterCharacterScripts. I already set up an IntValue to be checked to reward the killer. An error happens stating that "newplr" is nil when my script clearly says what that variable is. Is this an error relating to the limits of a Server Script accessing a player's leaderboard values? I tested this in a local script and I got the same results.

1 answer

Log in to vote
0
Answered by 6 years ago

It's occurring on lines 10 and 11, what does a player have to do with an Int Value?

What is "v.Name"?

What children of the character on line 9 have to do with the player's name?

0
v.Name of an IntValue inserted through a script is a name of a player that changes through a damage script in a tool. Line 9 is just finding the IntValue inside the character. InfernoExeuctioner 126 — 6y
Ad

Answer this question