Issue with leaderstats

Remember to open output if you haven’t already

1 Like

Red lines

you replaced too much, only relplace whats inside the red line

1 Like

I’ll give you the entire script since it might mess up the structure due to how roblox renders the spaces in code

PlayerService.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local deaths = Instance.new("IntValue")
	deaths.Name = "Deaths"
	deaths.Parent = leaderstats

	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = leaderstats

	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")

		-- Проверка на смерть
		humanoid.Died:Connect(function()
			-- Если персонаж уже мертв, не выполнять повторно обработку
			if humanoid.Health <= 0 then
				-- Увеличиваем количество смертей
				deaths.Value += 1

				-- Проверяем наличие "creator" у объекта, который причинил смерть
				local tag = humanoid:FindFirstChild("creator")
				print(tag, "tag") -- added
				if tag and tag.Value then
					local killer = tag.Value
					print(killer, "tag.value") -- added
					-- Увеличиваем количество убийств у убийцы
					if killer and killer:IsA("Player") then
						local killerStats = killer:FindFirstChild("leaderstats")
						print(killerStats, "killerstats") -- added
						if killerStats then
							local killerKills = killerStats:FindFirstChild("Kills")
							print(killerKills, "killerkills")  -- added
							if killerKills then
								killerKills.Value += 1
								warn(killer.Name, "Killed", player.Name)
							end
						end
					end
				end

				-- Удаляем объект "creator" после смерти
				if tag then
					tag:Destroy()
				end
			end
		end)
	end)
end)

Sorry forgot playerservice variable at the top, make sure to keep that

This is full script. Am I right?

It’s what i was sent minus the playerservice variable

Like this?

Yes

local PlayerService = game:GetService("Players")

PlayerService.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

Uh… Still doesn’t count
robloxapp-20241109-1343281.wmv (4.0 MB)

No you gotta check output to find where the code fails, the printing statements do not impact the script in any way they only make string comments show up on the output.

Here

Click on the red text

If you are still ingame it should show the script and line in question

what is the Selected instance parented to?

Also i cant see the onSelected function its not in the image

Here is image

Thank you, now could you go into workspace and search for the Selected part

Listen, Can I add you in Studio if you don’t mind?

I need to go in 5 minutes sadly so i cant be of much more help, i think you will need to make a new forum post because the problem is much bigger than just leaderboardstats.