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

Kill Reward System Not Working Properly?

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

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?

1 comment

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.

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