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

Script Not Functioning Right! Npc OnDeath Summons Item?

how would i create a npc that when it dies, summons an items that spawns on them? been trying to script this for a while now, here is my current script:

while true do
 	wait()
	if script.Parent.Humanoid.Health == "0" then
		Mod = game.ServerStorage.Lvl1Reward
		clone = Mod:clone()
		clone.Parent = workspace
		clone.Position = CFrame.new(script.Parent.Head)
		clone:MakeJoints()
		script.Parent:Destroy()
	end
end

The Script Doesnt Seem To Work, as it wont summon the item on the npc when it dies. If any of you guys know how to fix this, PLEASE HELP ME!

1 answer

✓ Accepted answer
function RewardItem(Level)
	local npc = script.Parent
	if Level == 1 then
		local mod = game.ServerStorage["Lvl1Reward"]:Clone()
		mod.Parent = workspace
		mod.Position = script.Parent.Head.Position
		mod:MakeJoints()
		print('Success, destroying...')
		npc:Destroy()
	elseif Level == 2 then
		local mod2 = game.ServerStorage["Lvl2Reward"]:Clone()
		mod2.Parent = workspace
		mod2.Position = script.Parent.Head.Position
		mod2:MakeJoints()
		print('Success, destroying...')
		npc:Destroy()
	end
end

-- If you're using DataStores, you can put whatever level the player is for userlevel.
UserLevel = nil -- replace nil with whatever, because I haven't seen your game and dont know what to put.
script.Parent.Humanoid.Died:Connect(RewardItem(UserLevel))

1 comment

0

okay, its amazing, however the script for 1. Doesnt need the if Level statements, its an npc that repspawns on death as well as the same thing. 2. for some reason the thing wont clone

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