|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|