Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you use a function more then once?

Asked by 6 years ago
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

0
Misleading title Programical 653 — 6y
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). chess123mate 5873 — 6y
0
Use return at the last line. Sebti23Drives 22 — 6y

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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)
Ad

Answer this question