generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How do I set a function in a tool that lasts forever?

Previous Thread :: Next Thread 
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
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 is not online. 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
IthacaMedia is not online. IthacaMedia
Joined: 25 Jan 2014
Total Posts: 1337
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
Eman1234567 is not online. Eman1234567
Joined: 19 Dec 2008
Total Posts: 6544
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
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
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 is not online. 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
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
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
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
22 Jan 2015 11:22 PM
Well this stinks
Report Abuse
DevConsole is not online. DevConsole
Joined: 02 Jun 2008
Total Posts: 460
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
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
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 is not online. 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 is not online. 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
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
22 Jan 2015 11:38 PM
I would use my script instead.
Pcall safeguard in mine (:
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
22 Jan 2015 11:43 PM
Your pcall safe guard is not efficient.
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
22 Jan 2015 11:44 PM
How so?
Report Abuse
128GB is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image