|
| 22 Jan 2015 09:05 PM |
Lets say in a local script in a tool, you place a part, when you touch said part you blow up.
But when you die, said part doesnt blow up anymore, how do I make it so when you die it can still kill you without putting a script inside it? |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 22 Jan 2015 09:08 PM |
| Why can you not put a script inside it |
|
|
| Report Abuse |
|
|
|
| 22 Jan 2015 09:19 PM |
| Put the script somewhere else, and use a variable that doesn't use script.Parent. You can run Touch events through player's Backpack's if you wanted too (I don't see why you would, lol). |
|
|
| Report Abuse |
|
|
|
| 22 Jan 2015 09:38 PM |
Alternatively this is a bit bass ackwards but you could also use boolean objects that generate as players enter (store them in the model in the workspace). Have the generated Boolean values be named after the player they correspond to. Have the script check if your player name's boolean is true or not before firing the explosion and if it's true, make the explosion, then set it to false. If you want this to be activated on death, you can also create a function that will fire for that. However, you can not accomplish this with only a local script, as the nature what you are trying to do is global. |
|
|
| Report Abuse |
|
|
|
| 22 Jan 2015 10:52 PM |
Putting the script inside the part and then having up to 30 of them seams kinda laggy or unefficent
|
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 22 Jan 2015 11:12 PM |
| Then have 1 script in ServerScriptStorage and have it effect all parts of a certain name and then name the bricks that |
|
|
| Report Abuse |
|
|
|
| 22 Jan 2015 11:19 PM |
| But I dislike the idea of loping though my game finding parts with a certain name :/ There really is no other way? |
|
|
| Report Abuse |
|
|
| |
|
|
| 22 Jan 2015 11:26 PM |
You don't have to loop anything just do:
for _,v in pairs(workspace:GetChildren()) do
if v.Name == 'NameOfKillBricks' then
v.Touched:connect(Function(Hit)
Hit.Parent:FindFirstChild('Humanoid').Health = 0
end)
the foreach will simply parse through workspace once, and create a connection for each of them. As long as the connection isn't broken, it will work. |
|
|
| Report Abuse |
|
|
|
| 22 Jan 2015 11:32 PM |
To be safe with Dev's script, you might want to quarantine the connection with a pcall and co routine. ----- nameOfBricks = "blah"; location = workspace; --Wherever they're located. I'm assuming workspace - change if necessary.
for i,v in pairs(location:GetChildren()) do coroutine.resume(coroutine.create(function() if v.Name == nameOfBricks then pcall(function() v.Touched:connect(function(hit) if game.Players:GetPlayerFromCharacter(v.Parent) then Instance.new("Explosion",hit).Position = hit end end) end) end end)) end |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 22 Jan 2015 11:34 PM |
local function touched(instance) print("omg u touch me") --do kill stuff end
function connect(instance) if (instance:IsA("BasePart") and (instance.Name == "connectPart")) do instance.Touched:connect(touched) end for _, child in next, instance do connect(child) end end
connect(workspace) workspace.DescendantAdded:connect(connect) |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 22 Jan 2015 11:36 PM |
Typo fixes
local function touched(instance) print("omg u touch me") --do kill stuff end
function connect(instance) if (instance:IsA("BasePart") and (instance.Name == "connectPart")) then instance.Touched:connect(touched) end for _, child in next, instance:GetChildren() do connect(child) end end
connect(workspace) workspace.DescendantAdded:connect(connect)
|
|
|
| Report Abuse |
|
|
|
| 22 Jan 2015 11:38 PM |
I would use my script instead. Pcall safeguard in mine (: |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 22 Jan 2015 11:43 PM |
| Your pcall safe guard is not efficient. |
|
|
| Report Abuse |
|
|
| |
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 22 Jan 2015 11:54 PM |
Well for starters coroutine.resume(coroutine.create(function()
That isn't needed
pcall should not be used unless it has to because its not efficient An example of having to use it would be
local function massProperty(instance, property, value) pcall(function() instance[property] = value end) --[[pcall is needed because roblox gives us no way to check if a property is a part of an object.]] for _, child in next, instance:GetChildren() do massProperty(child, property, value) end end
massProperty(workspace, "BrickColor", BrickColor.new("Bright red"))
|
|
|
| Report Abuse |
|
|
LucasLua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7386 |
|
|
| 23 Jan 2015 12:42 AM |
| Guarding against errors is inefficient because when you pass a function to the event connector, the function is ran on the event's thread, not your script's. Therefore if it errors it only breaks the connection. |
|
|
| Report Abuse |
|
|