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
 

Metal Detector

Previous Thread :: Next Thread 
Windows446 is not online. Windows446
Joined: 27 Jan 2010
Total Posts: 54
10 Jul 2011 12:50 PM
local activated = false


function onTouched(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if activated == true then return end
print 'Touched'
if human ~= nil then
g=hit.Parent.Name
h=game.Players:findFirstChild(g).Backpack:getChildren()
activated = true
if h == nil then
print 'Go'
script.Parent.Parent.GS.BrickColor = BrickColor.new(37)
wait(3)
script.Parent.Parent.GS.BrickColor = BrickColor.new(26)
else
print 'Stop weapon'
script.Parent.Parent.GS.BrickColor = BrickColor.new(1004)
script.Parent.Parent.Buzzer.Looped = true
script.Parent.Parent.Buzzer:Play()
wait(3)
script.Parent.Parent.Buzzer.Looped = false
script.Parent.Parent.Buzzer:Stop()
script.Parent.Parent.GS.BrickColor = BrickColor.new(1004)
activated = false
end end end

script.Parent.Touched:connect(onTouched)



Notes:
GS = indicator light.

The problem is that it will always return that there is something in the player's backpack when there is not. Someone help me please.
Thanks
Report Abuse
Jinxy is not online. Jinxy
Joined: 04 Aug 2007
Total Posts: 18317
10 Jul 2011 12:52 PM
did you specify h?
Report Abuse
Windows446 is not online. Windows446
Joined: 27 Jan 2010
Total Posts: 54
10 Jul 2011 12:52 PM
yep.
Report Abuse
Corecii is not online. Corecii
Joined: 06 Aug 2010
Total Posts: 687
10 Jul 2011 12:53 PM
GetChildren never returns nil.
When nothing is in an object it returns an empty table.
So:
if h == nil then
should be:
if #h <= 0 then
Report Abuse
Jinxy is not online. Jinxy
Joined: 04 Aug 2007
Total Posts: 18317
10 Jul 2011 12:54 PM
try:

function onTouched(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if activated == true then return end
print 'Touched'
if human ~= nil then
g=hit.Parent.Name
h=game.Players:findFirstChild(g).Backpack:getChildren()
activated = true
if h ~= nil then
print 'Go'
script.Parent.Parent.GS.BrickColor = BrickColor.new(37)
wait(3)
script.Parent.Parent.GS.BrickColor = BrickColor.new(26)
else
print 'Stop weapon'
script.Parent.Parent.GS.BrickColor = BrickColor.new(1004)
script.Parent.Parent.Buzzer.Looped = true
script.Parent.Parent.Buzzer:Play()
wait(3)
script.Parent.Parent.Buzzer.Looped = false
script.Parent.Parent.Buzzer:Stop()
script.Parent.Parent.GS.BrickColor = BrickColor.new(1004)
activated = false
end end end

script.Parent.Touched:connect(onTouched)


Report Abuse
Windows446 is not online. Windows446
Joined: 27 Jan 2010
Total Posts: 54
10 Jul 2011 12:55 PM
Works perfectly. Thanks!
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