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: function onTouched script help??

Previous Thread :: Next Thread 
tobymeyrick is not online. tobymeyrick
Joined: 13 Aug 2011
Total Posts: 1055
07 Jan 2012 05:34 PM
function onTouched(hit)
game.Lighting.Gun:Clone() .Parent = Players.LocalPlayer.Backpack
end
script.Parent.Touched:connect(onTouched)

I'm trying to get it to insert a Gun from lighting into the player who touched the script's parents backpack!!
Report Abuse
Grove537 is not online. Grove537
Joined: 05 Feb 2010
Total Posts: 3478
07 Jan 2012 05:35 PM
no space after ()
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
07 Jan 2012 05:37 PM
No space after ()

Plus, I would add a debounce.
Report Abuse
jimmybolt77 is not online. jimmybolt77
Joined: 06 Jul 2008
Total Posts: 292
07 Jan 2012 05:38 PM
game.Lighting.Gun:Clone() .Parent = Players.LocalPlayer.Backpack
I don't think you can use LocalPlayer. A messed up way to do what you want is-

function onTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") then --Making it zombie proof I think..
game.Lighting.Gun:Clone() .Parent = hit.Parent
end
script.Parent.Touched:connect(onTouched)

Might or might not work..
Report Abuse
tobymeyrick is not online. tobymeyrick
Joined: 13 Aug 2011
Total Posts: 1055
07 Jan 2012 05:40 PM
How do you debounce?
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
07 Jan 2012 05:43 PM
local deb = true
function onTouched(hit)
if deb == true then
deb = false
game.Lighting.Gun:Clone().Parent = Players.LocalPlayer.Backpack
wait(10)
deb = true
end
end
script.Parent.Touched:connect(onTouched)

That's better. Because if you don't add a debounce you can have muliple Guns in your backpack. But now it waits 10 seconds before you can get a gun again.
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
07 Jan 2012 05:46 PM
    function onTouched(hit)
        local playerObject = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if playerObject then
            local toolObject = game:GetService("Lighting"):FindFirstChild("Gun")
            if toolObject then
                local toolClone = toolObject:Clone()
                toolClone.Parent = playerObject.Backpack
            end
        end
    end
    
    script.Parent.Touched:connect(onTouched)

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
07 Jan 2012 05:48 PM
    local deBounce = false
    
    function onTouched(hit)
        if deBounce then return end
        deBounce = true
        local playerObject = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if playerObject then
            if not playerObject.Backpack:FindFirstChild("Gun") then
                local toolObject = game:GetService("Lighting"):FindFirstChild("Gun")
                if toolObject then
                    local toolClone = toolObject:Clone()
                    toolClone.Parent = playerObject.Backpack
                end
            end
        end
        deBounce = false
    end

Fixed, plus added debounce (which stops your script from running more than once).

script.Parent.Touched:connect(onTouched)

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
07 Jan 2012 05:48 PM
@Chronok

Eh...
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
07 Jan 2012 05:49 PM
...

    local deBounce = false
    
    function onTouched(hit)
        if deBounce then return end
        deBounce = true
        local playerObject = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if playerObject then
            if not playerObject.Backpack:FindFirstChild("Gun") then
                local toolObject = game:GetService("Lighting"):FindFirstChild("Gun")
                if toolObject then
                    local toolClone = toolObject:Clone()
                    toolClone.Parent = playerObject.Backpack
                end
            end
        end
        deBounce = false
    end
    
    script.Parent.Touched:connect(onTouched)

._.

Sorry... this should work.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
07 Jan 2012 05:50 PM
@chronok

Lol, no. I meant I didn't like that script.

1) You could of made it shorter

2) I dislike it when too many people use so much variables.
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
07 Jan 2012 05:56 PM
"You could of made it shorter"

So instead of doing this:

    local toolClone = toolObject:Clone()
    toolClone.Parent = playerObject.Backpack

I should have done this?

    toolObject:Clone().Parent = playerObject.Backpack

Sorry, but no. That makes for ugly code and I personally like my code to be nice and neat at maximum efficiency, which this is.

"I dislike it when too many people use so much variables."

Again, look at what I said above. If I hadn't made a variable, it would have made my code look ugly and unprofessional.

These are just my preferences, sorry if I offended you.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
07 Jan 2012 06:30 PM
@Chronok

The reason I don't like your code is because you use useless variable that you can just run the code instead.
Report Abuse
jdm281 is not online. jdm281
Joined: 15 Jan 2010
Total Posts: 177
07 Jan 2012 06:34 PM
Lol I love how the first two say "no space after ()" completely ignoring "LocalPlayer"
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
07 Jan 2012 06:41 PM
And....
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
07 Jan 2012 07:04 PM
@miz

Example of where I did so.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
07 Jan 2012 08:33 PM
@Chronok

You used 3 useless variables where you could of just ran the code.
Report Abuse
Vitouliss14 is not online. Vitouliss14
Joined: 18 Mar 2009
Total Posts: 7918
07 Jan 2012 08:36 PM
@miz656

What useless Varibles???
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
07 Jan 2012 10:27 PM
@Vit

He says variables that aren't the best because you could just run the code instead of saying all variables.
Report Abuse
Vitouliss14 is not online. Vitouliss14
Joined: 18 Mar 2009
Total Posts: 7918
08 Jan 2012 08:53 AM
I don't see any useless variables though. All of them are used for a good purpose.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
08 Jan 2012 01:17 PM
@Vitouliss

You don't get what I'm saying.

He uses the variables, it's just that you can run the code instead of having 3 lines of useless variables that he can run on one line.
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
08 Jan 2012 01:25 PM
@miz

I use the playerObject variable to check to see if the player exists. I then use it later to parent the cloned tool into the player's Backpack.

I use the toolObject variable (I think that's what I named it?) to check if the Gun object exists in Lighting, and I also use it later to get the toolClone variable.

I use the toolClone variable to get a clone of toolObject and then parent it into the player's Backpack.

All of my variables are used more than once, thus meaning that if I followed your idea, I would be running two chunks of code in the place of each of those variables each time.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
08 Jan 2012 01:32 PM
You don't get what I'm saying!!!!
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
08 Jan 2012 01:37 PM
@miz

Then post what you mean by copy and pasting my script with edits.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
08 Jan 2012 01:49 PM
@Chronok

I'm telling you! You use useless variables that ARE USED but you can just run the code simply instead of using them. Using variables is fine but using 4 variables in a script is uselss to me if you can just run the code on 1 or two lines.
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