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

How do you use a function more then once?

local character = workspace["Gem Monster"]

character:WaitForChild("Humanoid").Died:connect(function() --waitforchild to make sure its there
    redgem = Instance.new("Part",game.Workspace.GemDropStorage)
    redgem.Size = Vector3.new(1,1,1)
    redgem.Material = "Neon"
    redgem.BrickColor = BrickColor.new("Really red")
end)

When you kill the monster, it spanws a red part, which it is supposed to do then it respawns How do i edit the script to make it so i can kill it multiple times and every time it drops a brick

3 comments

0

Misleading title

0

A simple solution to your problem is to put this script (that generates the red part) as a direct child of the Gem Monster (since you presumably :Clone() it elsewhere in order to respawn it).

0

Use return at the last line.

1 answer

Well lets say that all of our monsters are located inside a folder or model we will make it so that whenever a new monster is added to that folder it will make it so that if it dies it will fire this

First we will add a childadded event

local folder=workspace.Monsters

folder.ChildAdded:connect(function(child)

end)

Next to add that died event function

local folder=workspace.Monsters

folder.ChildAdded:connect(function(child)
	child:WaitForChild("Humanoid").Died:connect(function()
		redgem = Instance.new("Part",game.Workspace.GemDropStorage)
		redgem.Size = Vector3.new(1,1,1)
		redgem.Material = "Neon"
		redgem.BrickColor = BrickColor.new("Really red")
	end)
end)

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