|
| 29 Jan 2012 07:35 PM |
Alright, so this is my script right now.
cannonBall = game.Workspace.Cannon Shot
function Touched(hit) if hit == cannonBall then script.Parent.Transparency = 1 end end
script.Parent.Touched:connect(touched)
My objective: To turn invisible when hit by the Cannon Ball, and ONLY by the Cannon Ball.
Results: Nothing. |
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 07:36 PM |
| The part "Cannon Shot" does not exist until the weapon is fired, is that a problem? |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 29 Jan 2012 07:37 PM |
| cannonBall = game.Workspace["Cannon Shot"] |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 29 Jan 2012 07:37 PM |
cannonBall = game.Workspace.CannonShot--Make this one word. script.Parent.Touched:connect(function(hit) if hit.Name == cannonBall then script.Parent.Transparency = 1 end end)
|
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 07:44 PM |
| Tried both... neither worked. |
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 07:45 PM |
It says in the output
"CannonShot is not a valid member of Workspace" |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 29 Jan 2012 07:45 PM |
Then its a problem on your side. I fixed an obvious error in your script.
|
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 07:48 PM |
script.Parent.Touched:connect(function(hit) if hit.Name == "Cannon Shot" then script.Parent.Transparency = 1 end end)
Make the name of the cannon ball 'Cannon Shot' without 's And yes, indexing a part that isn't there results in error |
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 07:51 PM |
*Facepalm*
while not game.Workspace:findFirstChild("Cannon Shot") do wait() end
db = false
script.Parent.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid") then if db == false then db = true script.Parent.Transparency = 1 db = false end end end)
`*\~-{ Are we there yet T.T? }-~/*` |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 29 Jan 2012 07:59 PM |
Cannonshot == nil
If it's not in Workspace, then it must've been removed... |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 29 Jan 2012 08:11 PM |
When you make a variable part and then remove the part, it doesn't make the variable nil.
|
|
|
| Report Abuse |
|
|
palk47
|
  |
| Joined: 07 May 2009 |
| Total Posts: 508 |
|
|
| 29 Jan 2012 08:14 PM |
1. No spacing in "CannonShot" because Lua is picky. 2. "hit.Parent.Transparency = 1" won't work because a group does not have a transparency property. You must use:
g = hit.Parent for i = 1,#g do if g[i].ClassName == "Part" then g[i].Part.Transparency = 1 end end |
|
|
| Report Abuse |
|
|
palk47
|
  |
| Joined: 07 May 2009 |
| Total Posts: 508 |
|
|
| 29 Jan 2012 08:15 PM |
Whoops... MY bad. I thought hit's parent was the robloxian itself.... |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 29 Jan 2012 08:16 PM |
@hathelper
This is what I meant
Output CannonShot is not a valid member of Workspace
If CannonShot is not in Workspace anymore it's nil. |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
| |
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 29 Jan 2012 08:23 PM |
I'm not saying the script doesn't work because of the output I'm just saying if it's not a valid member of workspace, where would it be?
Not a valid member of workspace
so it's nil. |
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 08:23 PM |
... What I posted should work.
And yes, it is nil if it did not exist in the Workspace before a script attempts to index it, which is exactly what OP said about 'Cannon Shot' |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 29 Jan 2012 08:25 PM |
OH I BEAT A 14-16 YEAR OLD MIDGET(hathelper)
YEAH!!!!:P |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 29 Jan 2012 08:27 PM |
"If CannonShot is not in Workspace anymore it's nil."
You are incorrect, either language-wise, or script wise.
I know far more than you. "If CannonShot is not in Workspace ANYMORE it's nil. It is not nil, ignorant infant,
Part=Instance.new("Part") Part.Parent = workspace Part.Name = "Cannon Shot" a=workspace.Part Part:remove() print(a)
And there is your proof. |
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 08:28 PM |
"And yes, it is nil if it did not exist in the Workspace before a script attempts to index it"
It isn't nil, it just doesn't exist. There's a difference.
@miz Please stop with your spam. It's getting annoying. |
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 08:31 PM |
| @AgentFireFox Could you explain the difference? I just assumed it would be considered nil considering that's what would be returned since it does not exist. |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 29 Jan 2012 08:32 PM |
If it never existed, you can't get it. But if it DID exist, it doesn't matter what you did with it, if you made it a variable, it exists somewhere until you nil the variable.
Which is why he is wrong, by what he said.
|
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 08:33 PM |
Because nil is a value all in itself. If the part doesn't exist in workspace (or any object for that matter), there is no value associated with the object. Because it has not been created.
If you try to index the part, you will get an error. Because there is no value associated with the part. The only way you would get get nil as the value is if you use FindFirstChild, and that's because the FindFirstChild method will return nil. |
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 08:35 PM |
| @HatHelper, Thanks for the distinction. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 29 Jan 2012 08:35 PM |
@Hathelper
Derp. I didn't think of it that way. I guess the 13 year old boi loses to the 16 year old guy with chesthairs.
@Aff
I'm adhd, you think I can help it? |
|
|
| Report Abuse |
|
|