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: If Player comes close to Brick then do... Doesn't Function?

Previous Thread :: Next Thread 
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
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
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
11 Jun 2014 01:52 PM
Someone D:?
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
11 Jun 2014 01:53 PM
have the variable 'vanishing' not local
Report Abuse
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
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
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
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
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
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
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
11 Jun 2014 03:08 PM
Please D:?
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
11 Jun 2014 03:11 PM
It means (vanishing.Torso.Position-script.Parent.Position).magnitude is not less than 20.
Report Abuse
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
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
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
12 Jun 2014 08:49 AM
Help D:?
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
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
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
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
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
12 Jun 2014 11:08 AM
Anyone?
Report Abuse
1234Christopher is not online. 1234Christopher
Joined: 21 Oct 2008
Total Posts: 1715
12 Jun 2014 11:12 AM
A few errors, you're a little ahead of your self :P
Report Abuse
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
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 is not online. Perci1
Joined: 24 Jan 2011
Total Posts: 1027
12 Jun 2014 11:21 AM
Put you functions outside the for loop...
Report Abuse
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
12 Jun 2014 11:23 AM
So delete the for loop?
Report Abuse
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
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
planesoldier is not online. planesoldier
Joined: 26 Sep 2010
Total Posts: 533
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
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