ObjectValue not getting value

local work = game:GetService("Workspace")
local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = leaderstats
	local deaths = Instance.new("IntValue")
	deaths.Name = "Deaths"
	deaths.Parent = leaderstats
	local totalkills = Instance.new("IntValue")
	totalkills.Name = "Total kills"
	totalkills.Parent = leaderstats
	local streak = Instance.new("IntValue")
	streak.Name = "Streak"
	streak.Parent = leaderstats
	player.CharacterAdded:Connect(function(char)
		task.wait()
		local Humanoid = char:FindFirstChild("Humanoid")
		local root = char:WaitForChild("HumanoidRootPart", 10)
		local pos = Vector3.new(math.random(0,253), 30, math.random(0,253))
		char:MoveTo(pos)
		print("Spawned "..char.Name.." at "..tostring(pos))
		if not Humanoid:FindFirstChild("Killer") then
			local new_tag = Instance.new("ObjectValue")
			new_tag.Name = "Killer"
			new_tag.Parent = Humanoid
		end
		Humanoid.Died:Connect(function(died)
			deaths.Value += 1
			streak.Value = 0
			local tag = Humanoid:FindFirstChild("Killer")
			local killer = tag.Value
			if tag and killer and killer ~= nil and killer ~= player then
				killer.leaderstats:FindFirstChild("Kills").Value += 1
				killer.leaderstats:FindFirstChild("Streak").Value += 1
			end
		end)
	end)
end)

I have an error in last line, it says leaderstats is not a part of player.

			local tag = Humanoid:FindFirstChild("Killer")
			local killer = tag.Value
			if tag and killer and killer ~= nil and killer ~= player then
				killer.leaderstats:FindFirstChild("Kills").Value += 1
				killer.leaderstats:FindFirstChild("Streak").Value += 1
			end

Does the error mention the player? If so, then the object value IS getting the value. Try using killer:WaitForChild("leaderstats") instead of killer.leaderstats

1 Like

yes it mentions the player, leader stats are created as soon as player joins the game so there shouldnt be an issue, also error happens every single time

Still can’t hurt to use :WaitForChild() though.

just to check, the tag killer refers to a PLAYER, not to a player’s character, right?

1 Like

yeah, it uses the player, still isnt working, i thought maybe it was an issue with getting value out of objectvalue

Where’s the code that inserts the Killer tag into the player?

1 Like

I fixed it, i was setting killer value as humanoid instead of the player…