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 » Scripting Helpers
Home Search
 

Re: can someone help me right an end statement

Previous Thread :: Next Thread 
unknown1616 is not online. unknown1616
Joined: 04 Nov 2009
Total Posts: 1025
02 Apr 2012 08:48 PM
script.Parent.Touched:connect(function(hit)
if hit.Parent["Humanoid"] then
local g=hit.Parent.Name
local h=game.Players[g].Backpack:GetChildren()
for i=1, #h do
if h[i]:IsA("Tool") and h[i].Name == "Gun" then
h[i]:Destroy()
end
end
end

I was never good at makeing them
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
02 Apr 2012 08:54 PM
script.Parent.Touched:connect(function(hit)
if hit.Parent["Humanoid"] then
local g=hit.Parent.Name
local h=game.Players[g].Backpack:GetChildren()
for i=1, #h do
if h[i]:IsA("Tool") and h[i].Name == "Gun" then
h[i]:Destroy()
end
end
end
end)
Report Abuse
Defendur is not online. Defendur
Joined: 31 Mar 2012
Total Posts: 40
02 Apr 2012 09:48 PM
Can you tell me why you use :connect(function(hit)

instead of

function touched(hit)
if hit.Parent["Humanoid"] then
local g=hit.Parent.Name
local h=game.Players[g].Backpack:GetChildren()
for i=1, #h do
if h[i]:IsA("Tool") and h[i].Name == "Gun" then
h[i]:Destroy()
end
end
end
end

script.Parent.Touched:connect(touched)

I'm being serious, this must be something new in the past few years. :o
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
02 Apr 2012 09:54 PM
No it isn't, it's called an anonymous function. As the name suggests, it's an unnamed function.
Report Abuse
Defendur is not online. Defendur
Joined: 31 Mar 2012
Total Posts: 40
02 Apr 2012 09:59 PM
I'm pretty sure it's new.. We never had these in 08.
Report Abuse
unknown1616 is not online. unknown1616
Joined: 04 Nov 2009
Total Posts: 1025
02 Apr 2012 10:01 PM
Its becasue the scripts are becomeing more bigger and better, so its a way so the scripts can go easyer.
Report Abuse
unknown1616 is not online. unknown1616
Joined: 04 Nov 2009
Total Posts: 1025
02 Apr 2012 10:04 PM
@ElectricBlaze
you script works, but still disconects after one hit.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
03 Apr 2012 05:07 PM
@Defendur - I was here in 2008 too, I would know. Also, Anonymous Functions are something that were not created by ROBLOX - they're from Lua. I'm not even sure ROBLOX *can* get rid of anonymous functions, as technically, all functions are anonymous. What I mean by that is that when you give a function a name, you're really only creating a variable and putting the function inside. Try this:

    (function() print"Hello World!" end)()

It works just as well as:

    function hello()
        print"Hello World!"
    end
    hello()
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
03 Apr 2012 05:12 PM
@unknown - Of course it disconnects after one hit, after it deletes your guns, you don't have them anymore. I'm just going to rewrite your code to make it look better.

    local deb = false
    script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and not deb then
    deb = true
    for k,v in pairs(game.Players[hit.Parent.Name].Backpack:GetChildren()) do
    if v:IsA("Tool") and v.Name == "Gun" then
    v:Destroy()
    end
    end
    end
    wait(1)
    deb = false
    end)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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