Player not found in player tag

I’m trying to make a script,that’s upon a boss’s death,give its killer a badge,but it won’t find the player from creator tag.Here’s the script:

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local npcc = workspace:WaitForChild("npc")

local badgeId = 50950130779050 
local awardBadgeEvent = ReplicatedStorage:FindFirstChild("AwardBadgeEvent")

local function onNPCDeath(npc)
	local humanoid = npc:FindFirstChild("Humanoid")
	if humanoid then
		local creatorTag = humanoid:FindFirstChild("creator")
		if creatorTag and creatorTag:IsA("ObjectValue") and creatorTag.Value then
			local player = Players:GetPlayerFromCharacter(creatorTag.Value)
			if player then
				BadgeService:AwardBadge(player.UserId, badgeId)
			else
				warn("Player not found from creator tag")
			end
		else
			warn("Creator tag not found or invalid")
		end
	else
		warn("Humanoid not found in NPC")
	end
end

npcc:WaitForChild("Humanoid").Died:Connect(function() 
	onNPCDeath(npcc) 
end)

Are you sure you’re storing the player’s character in the creatorTag, or are you storing the player object directly?

Other than that, your code looks good.

does it mean anything? like what is the difference?

In your script, you’re getting the character object from the tag. This would not work if the tag already referenced the player. You can’t call Players:GetPlayerFromCharacter() on a player object.

I’d double check if you’re storing the player’s character in the objectvalue, or the player’s playerobject.

1 Like

i am a newbie scripter,so i have some problems understanding the creator tag thing,can you please explain what should i do in detail?

Could you show the script where you create the CreatorTag and set the value?

1 Like

this is the whole script,what do you need?

How is the CreatorTag created? I am assuming it is when the NPC itself is created, could you show that?

i am not creating it? isn’t it suppose to be there already?

Question I should’ve asked earlier: Why do you need an NPC when rewarding a badge to a player? Is the NPC the boss? If so, then I assume the creator tag is the person who last dealt damage to the boss. You could make it so the damage script of the player (like a sword) changes the creator value upon attacking.

so what is the best way to do it?

Nope. This is not a feature of the Roblox engine. You must create the behaviour itself

How can i create the creator value though?

What kind of damage method do the players have? Sword? Gun?

In the script for this weapon or whatever it is, in the section that contains the code that damages the boss, add a few lines that check if the boss’ humanoid’s health is above 0 (to prevent stealing kills) and if it is, set the creator value to the player.

It’s best if you prefabricate it in Roblox Studio as a child of your NPC. Your weapons need to find this value and assign its wielder to it each time it harms the NPC. Only assign to the value while the NPC is alive

add an ObjectValue to the humanoid of the npc named creator

if you don’t want to do this and want to do it with a script, you can use Instance.new() to create an instance and use .Name to change its name and .Parent to parent it to the humanoid

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.