Help with xp problem Reward

hi i have problem with 2 exp everything work but i have problem with reward from npc they kill that npc script reward

local Enemy = script.Parent.Humanoid
function KillForXp() 
	local nume = 100
local tag = Enemy:findFirstChild("creator") 
	if tag ~= nil then 
		if tag.Value ~= nil then 
local Data = tag.Value:findFirstChild("Data") 
local leader = tag.Value:FindFirstChild("Quest")
if leader.Num.Value == script.Parent.Data.Num.Value then
          if leader ~= nil then
        leader.Kills.Value = leader.Kills.Value + 1
   end
end
			if Data ~= nil then 
				if Data.Expx2.Value < 0 then
					Data.Exp.Value += nume
				elseif  Data.Expx2.Value > 0 then
					Data.Exp.Vaule += (nume * 2)
				
				
				
wait(0.01) 
script:Destroy()
			end 
		end 
	end 
		end
	Enemy.Died:connect(KillForXp) 
	end

You misspelt it, this should be FindFirstChild, tho - I’d use WaitForChild, since the creator tag is not automatically added under the humanoid.

Also, instead of wait, use task.wait [more efficient and accurate].

Apart from the issues and recommendations by @Valkyrop, please format your document correctly. It is currently very hard to read. If you are unsure how to properly format it, press the button “format document” in the scripting view.

this is the normal script without 2xp reward

local Enemy = script.Parent.Humanoid
function KillForXp() 
local tag = Enemy:findFirstChild("creator") 
	if tag ~= nil then 
		if tag.Value ~= nil then 
local Data = tag.Value:findFirstChild("Data") 
local leader = tag.Value:FindFirstChild("Quest")
if leader.Num.Value == script.Parent.Data.Num.Value then
          if leader ~= nil then
        leader.Kills.Value = leader.Kills.Value + 1
   end
end
if Data ~= nil then 
Data.Beli.Value = Data.Beli.Value + 100
Data.Exp.Value = Data.Exp.Value + 100
				
wait(0.01) 
script:Destroy()
			end 
		end 
	end 
		end
Enemy.Died:connect(KillForXp) 

Is Data.Expx2.Value == 0? If that is the case, then no xp will be awarded.

no the value it number you can buy it but when i kill npc i dont get any reward

Have you tried adding some prints? To see where it stops working?

1 Like