Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I get an enemy to drop exp/gold when killed?

I have an enemy (squirrel) that I want to give exp and gold when killed. This is my leaderboard script:

game.Players.PlayerAdded:connect(function(player)
		local stats = Instance.new('IntValue', player)
	stats.Name = 'leaderstats'

		local level = Instance.new('IntValue', stats)
	level.Name = 'Level'
	level.Value = 1

		local gold = Instance.new('IntValue', stats)
	gold.Name = 'Gold'
	gold.Value = 0

		local experience = Instance.new('IntValue', stats)
	experience.Name = 'Exp'
	experience.Value = 0

end)

I'm kind of new to Lua.

1 answer

✓ Accepted answer

I'd start by having some way to know who killed the enemy, like a value that changes to the name of the last player to affect it's health. From there, you'd find the player and say

experience .Value = experience . Value + 1

Humanoid.Died will help you out with following the monsters death

(See http://wiki.roblox.com/index.php?title=API:Class/Humanoid/Died)

Hope this helped in the slightest.

This discussion is preserved as it was. New answers, comments, and votes are closed.