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 » Scripters
Home Search
 

Check for tool

Previous Thread :: Next Thread 
DaveHereYouTube is not online. DaveHereYouTube
Joined: 13 May 2016
Total Posts: 213
17 Aug 2016 10:41 PM
I have a script that checks if the player has a tool in their backpack or on their character every second. Problem is that if the player equips and unequips the tool very quickly and repetitively the script will add another tool. Other then that the script works great. How else can I do this?

function Tele(player)
if player.Variable.TalkedKorin.Value == 4 then //Checks to see if the play should have teleport
for i, v in pairs(player.Backpack:GetChildren()) do
if v.Name == "Teleport" then
found1 = true
else
found1 = false
end
end
for i, v in pairs(player.Character:GetChildren()) do
if v.Name == "Teleport" then
found2 = true
else
found2 = false
end
end
if found1 == false and found2 == false then
Teleport = game.Lighting.Teleport:Clone()
Teleport.Parent = player.Backpack
end
end
end
Report Abuse
infortality is not online. infortality
Joined: 28 May 2012
Total Posts: 942
18 Aug 2016 02:35 AM
You have to use 'break' after you set found1/found2 to true, because otherwise the loop will continue and set it back to false.
However, there is a much shorter way to write this function:

function Tele(player)
if player.Variable.TalkedKorin.Value == 4 then
if not (player.Backpack:FindFirstChild("Teleport") or player.Character:FindFirstChild("Teleport")) then
game.Lighting.Teleport:Clone().Parent = player.Backpack
end
end
end
Report Abuse
DaveHereYouTube is not online. DaveHereYouTube
Joined: 13 May 2016
Total Posts: 213
18 Aug 2016 07:59 PM
Wow infortality! That worked great. I hate it when I don't think of a simpler way of doing something. Your script makes so much more sense. I'll come back to this script when I need to do checks in the future. Thanks!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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