How to give players coins depends on which npc they kill?

The title says all but. I am trying to give players depends on the npc they killed

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local ServerScriptService = game:GetService("ServerScriptService")
local Npc = script.Parent
local NPCHumanoid = Npc:WaitForChild("Humanoid")
local NpcModule = require(ServerScriptService.NPCs)

if NPCHumanoid then -- Checks Humanoid
	NPCHumanoid.Died:Connect(function()
		print("Test1")
		local npcTagger = NPCHumanoid.Montaigne.Value 
		if npcTagger ~= nil then --Check the tag
			print("Test2")
			local player = game:GetService("Players"):GetPlayerFromCharacter(npcTagger)
			print(player.Name)
			if player then
				print("Test3")
		for i , v in pairs(NpcModule) do
					player.leaderstats.Coins += v.Coins
					
		end		
		end			
		end

	end)
end

this is the module script
Screenshot_134

it doesn’t print player.Name and Test3
it gives 400 coins even if player just kills the “Noob” npc

Does the dictionary array match the npc name? if so you can just use

Humanoid.Died:Connect(function()
	Player.leaderstats.Coins.Value += NpcModule[NPC.Name].Coin
end)

It works like this.
image

1 Like

they match

You need to use your way to get player which is.
local player = game:GetService("Players"):GetPlayerFromCharacter(npcTagger) in your case.

Nope still same error

I don’t know why but it trys to find leaderstats inside the npc not player

What is hitter suppose to be? objectvalue or?

Yep it is an ObjectValue 30<-< letter

To get player from objectvalue you either use two of these. That is I assume it’s an actual player object and not character model,

local player = game:GetService("Players"):FindFirstChild(tostring(NPCHumanoid.Hitter.Value))
local player = NPCHumanoid.Hitter.Value
1 Like

it works now! Thank you!
30 thing again

1 Like

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