First of all, I have no idea what I was doing after the first couple of lines. I was trying to figure out how to make a lot of bricks at one time earlier and It got answered, but then I thought, how about make them kill you as well. Well... I successfully failed. I got them to spawn a lot but I wanted each and every one of them kill you if you touched them. So I tried and here it went
while true do wait(0.3) Part = Instance.new("Part", workspace) Part.Position = Vector3.new(workspace.Spawner) function KillBrick() local h = Instance.new("Part", workspace) if h.Parent:FindFirstChild("Humanoid") then if h.Parent~= 0 then h.Parent.Humanoid.Health = 0 end end end script.Parent.Touched:connect(KillBrick) Part.BrickColor = BrickColor.new("Really Red") wait(0.1) end
Also, I wanted to know how would I edit that brick everytime it spawns. For example, I was trying to figure out how to make the brick red or yellow or something....
Although it's good to push yourself, writing random code when you have no idea how it works or what it does is never a good idea.
You can't make a part's position workspace.Spawner
, because Spawner is an object, not a Vector3 value. You must make the part's position equal to the spawner's position.
Keep in mind what your variables equal; on line 07 you create a part stored in the variable h
, then check if it has a Humanoid. Since you never create a Humanoid, obviously the created part will never have a Humanoid!
h
is in no way connected to the person who touched the Part.
Here it would be best to use an anonymous function so that you can easily connect the Touched event to each part created. Although anonymous functions can be confusing, they're an easy thing to memorize without completely understanding how they technically work. We're basically going to be giving the connect()
method an argument which is a function, which will run whenever the event we connected it to is fired.
while true do wait(0.5) local part = Instance.new("Part",workspace) --Create the part part.Position = workspace.Spawner.Position--Position it part.BrickColor = BrickColor.new("Really red") --Change the color part.Touched:connect(function(hit)--Connect touched event to it if hit.Parent:FindFirstChild("Humanoid") then--Look for humanoid of part that touched it hit.Parent.Humanoid.Health = 0--Set health to 0 if humanoid exists end end) end
You Can Do It Like This (You Will Need To Build First.):
function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) then -- if a humanoid exists, then humanoid.Health = 0 -- damage the humanoid end end script.Parent.Touched:connect(onTouch)
Now Make A New Script And Do This:
script.Parent:Clone() wait (1.5) script.Parent:Clone() wait (1.5) script.Parent:Clone() wait (1.5) script.Parent:Clone() wait (1.5) script.Parent:Clone() wait (1.5) script.Parent:Clone() wait (1.5) script.Parent:Clone() wait (1.5) script.Parent:Clone()
(Put This In The Command Bar If You Want To Add The Parts Now.):
game.Workspace.KillPart:Clone() wait (1.5) game.Workspace.KillPart:Clone() wait (1.5) game.Workspace.KillPart:Clone() wait (1.5) game.Workspace.KillPart:Clone() wait (1.5) game.Workspace.KillPart:Clone() wait (1.5) game.Workspace.KillPart:Clone() wait (1.5) game.Workspace.KillPart:Clone() wait (1.5) game.Workspace.KillPart:Clone()