I’m trying to make a system where if you kill an NPC you get 5 coins, and if you kill a player you get 10 coins. How would I go about doing this?
1 Like
uh
drop the coin when theyre dead maybe
can you show how your coin system works?
1 Like
Not like that. It’s a leaderstat just named “Coins”. It’s the same as “Cash” or “Money”.
You could add a tag to the NPC when the player deals damage and give coins to the player that tagged the NPC when it dies.
local function damage(attacker: Player, target: Model & {Humanoid}, damage: number)
target.Humanoid:TakeDamage(damage)
local tag = target:FindFirstChild("DamagedBy")
if not tag then
tag = Instance.new("ObjectValue")
tag.Name = "DamagedBy"
end
tag.Value = attacker
tag.Parent = target
end
npc.Humanoid.Died:Connect(function()
local tag = npc:FindFirstChild("DamagedBy")
if tag then
tag.Value.leaderstats.Coins.Value += 5
end
end)
2 Likes
You may want to add a destroy timer on the tag so you don’t get awarded for kills long after the fact, similar to the tagging system Roblox used to employ in its old gears/brickbattle tools.
It’s up to the OP if they want to add that, my script was just an example.