|
| 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
|
  |
| Joined: 05 Feb 2010 |
| Total Posts: 3478 |
|
| |
|
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 |
|
|
|
| 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 |
|
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|
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
|
  |
| 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 |
|
|
|
| 07 Jan 2012 08:36 PM |
@miz656
What useless Varibles??? |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 08 Jan 2012 01:32 PM |
| You don't get what I'm saying!!!! |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|