|
| 11 Jun 2014 01:42 PM |
Hey There!
I have a script that should enable a light when a specific model comes close, however, it doesnt function.. This is the Error:
20:39:58.686 - Workspace.Players.TestPlayer.Torso.Light:13: attempt to index global 'vanishing' (a nil value)
And this is the Script:
for _, player in pairs(game.Players:GetPlayers()) do function randomVanishing() local vanishingcharacter = game.Workspace.Vanishing:GetChildren() return vanishingcharacter[math.random(#vanishingcharacter)] end local vanishing=randomVanishing() function check() if (vanishing.Torso-script.Parent).magnitude<10 then script.Parent.SurvivorsLight.Enabled=true end end end vanishing.Torso.Changed:connect(check) script.Parent.Changed:connect(check)
Any Help :D? THX! Planesoldier |
|
|
| Report Abuse |
|
|
| |
|
|
| 11 Jun 2014 01:53 PM |
| have the variable 'vanishing' not local |
|
|
| Report Abuse |
|
|
|
| 11 Jun 2014 02:01 PM |
Then it gives this:
21:00:35.322 - Workspace.Players.TestPlayer.Torso.Light:8: attempt to perform arithmetic on field 'Torso' (a userdata value) |
|
|
| Report Abuse |
|
|
|
| 11 Jun 2014 02:03 PM |
'vanishing.Torso-script.Parent' You cant subtract objects. I think youre trying to subtract position 'vanishing.Torso.Position-script.Parent.Position' |
|
|
| Report Abuse |
|
|
|
| 11 Jun 2014 02:18 PM |
I did this now:
for _, player in pairs(game.Players:GetPlayers()) do function randomVanishing() local vanishingcharacter = game.Workspace.Vanishing:GetChildren() return vanishingcharacter[math.random(#vanishingcharacter)] end vanishing=randomVanishing() function check() if (vanishing.Torso.Position-script.Parent.Position).magnitude<20 then script.Parent.SurvivorsLight.Enabled=true vanishing.Torso.Position.Changed:connect(check) script.Parent.Position.Changed:connect(check) end end end
But now it doesnt do anything, no errors, no functioning.... Please help D: |
|
|
| Report Abuse |
|
|
| |
|
|
| 11 Jun 2014 03:11 PM |
| It means (vanishing.Torso.Position-script.Parent.Position).magnitude is not less than 20. |
|
|
| Report Abuse |
|
|
|
| 11 Jun 2014 03:25 PM |
| When i stand right next to it, or on it it doesnt do anything... So i think 20 is enough... |
|
|
| Report Abuse |
|
|
| |
|
|
| 12 Jun 2014 09:09 AM |
"vanishing.Torso.Position.Changed:connect(check)" You don't hook the Changed event to a property of an object, but rather the object itself. |
|
|
| Report Abuse |
|
|
|
| 12 Jun 2014 09:30 AM |
Still wont work... I use this now:
function randomVanishing() local vanishingcharacter = game.Workspace.Vanishing:GetChildren() return vanishingcharacter[math.random(#vanishingcharacter)] end vanishing=randomVanishing() function check() vanishing.Torso.Changed:connect(check) script.Parent.Changed:connect(check) if (vanishing.Torso.Position-script.Parent.Position).magnitude<20 then script.Parent.SurvivorsLight.Enabled=true end end |
|
|
| Report Abuse |
|
|
| |
|
|
| 12 Jun 2014 11:12 AM |
| A few errors, you're a little ahead of your self :P |
|
|
| Report Abuse |
|
|
|
| 12 Jun 2014 11:14 AM |
| But i want to make it. And from making errors you learn :3. But i really need it. Please help D:? |
|
|
| Report Abuse |
|
|
Perci1
|
  |
| Joined: 24 Jan 2011 |
| Total Posts: 1027 |
|
|
| 12 Jun 2014 11:21 AM |
| Put you functions outside the for loop... |
|
|
| Report Abuse |
|
|
| |
|
|
| 12 Jun 2014 11:33 AM |
ow wait, i was being stupid... This is it now, but it still doesnt do anything...
function randomVanishing() local vanishingcharacter = game.Workspace.Vanishing:GetChildren() return vanishingcharacter[math.random(#vanishingcharacter)] end vanishing=randomVanishing() function check() if (vanishing.Torso.Position-script.Parent.Position).magnitude<20 then script.Parent.SurvivorsLight.Enabled=true end end vanishing.Torso.Changed:connect(check) script.Parent.Changed:connect(check) |
|
|
| Report Abuse |
|
|
|
| 12 Jun 2014 12:01 PM |
| Okay, so i found out it doesnt loop, but when i use while true do studio crashes... And in-game it says 'Script Failed' |
|
|
| Report Abuse |
|
|