|
| 07 Oct 2015 12:32 AM |
function onTouched(hit) if hit.Parent:findFirstChild("Humanoid") then local tools = hit.Parent.Backpack:GetChildren() for i = 1,#tools do tools[i]:Remove() end end end script.Parent.Touched:connect(onTouched)
This doesn't work and I have no idea why. |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2015 12:43 AM |
local debounce = false script.Parent.Touched:connect(function(hit) if debounce then return end debounce = true if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then for _, tool in next, game.Players:GetPlayerFromCharacter(hit.Parent).Backpack:GetChildren() do if tool:IsA("Tool") or tool:IsA("HopperBin") then tool:Destroy() end end for _, tool in next, hit.Parent:GetChildren() do if tool:IsA("Tool") or tool:IsA("HopperBin") then tool:Destroy() end end end wait(.2) debounce = false end)
Try that.
-The [Guy] |
|
|
| Report Abuse |
|
|
| |
|
|
| 07 Oct 2015 01:34 AM |
| Thank you IT WORKED, but I need help on one more thing. Do you know how to limit the number of tools that a player can have ? |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2015 04:07 PM |
You could use a script like this to check how many tools they have when a tool is added and if it's over the legal limit (lol) then it will delete it. Be careful with this, because if they have to purchase something, it will still let them purchase it, but it will delete it.
local maxTools = 6 script.Parent.ChildAdded:connect(function() local numTools = 0 for _, tool in next, script.Parent:GetChildren() do if tool:IsA("Tool") or tool:IsA("HopperBin") then numTools = numTools + 1 if numTools > maxTools then tool:Destroy() end end end end)
-The [Guy] |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2015 06:08 PM |
| It worked, but for some reason the tool name in the toolbar didn't get destroyed as well |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 07 Oct 2015 06:11 PM |
Try this:
local maxTools = 6 game.Players.LocalPlayer.StarterGear.ChildAdded:connect(function() local numTools = 0 for _, tool in next, script.Parent:GetChildren() do if tool:IsA("Tool") or tool:IsA("HopperBin") then numTools = numTools + 1 if numTools > maxTools then tool:Destroy() end end end end)
u sicko! |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2015 06:27 PM |
It didn't work for me. I have the script in a local script in starter pack. |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2015 08:30 PM |
local maxTools = 6 script.Parent.ChildAdded:connect(function() local numTools = 0 for _, tool in next, script.Parent:GetChildren() do if tool:IsA("Tool") or tool:IsA("HopperBin") then numTools = numTools + 1 if numTools > maxTools then tool:Destroy() end end end
for _, tool in next, script.Parent:GetChildren() do if tool:IsA("Tool") or tool:IsA("HopperBin") then numTools = numTools + 1 if numTools > maxTools then tool:Destroy() end end end for _, tool in next, script.Parent.Parent.Character:GetChildren() do if tool:IsA("Tool") or tool:IsA("HopperBin") then numTools = numTools + 1 if numTools > maxTools then tool:Destroy() end end end end)
Okay, I'm not sure if I understood what your issue with the last one was but maybe it was that a tool that is equipped didn't get deleted? This script checks for that too, so keep this in the StarterPack.
-The [Guy] |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2015 08:31 PM |
Oh my gosh, sorry, c/p error. Here:
local maxTools = 6 script.Parent.ChildAdded:connect(function() local numTools = 0 for _, tool in next, script.Parent:GetChildren() do if tool:IsA("Tool") or tool:IsA("HopperBin") then numTools = numTools + 1 if numTools > maxTools then tool:Destroy() end end end for _, tool in next, game.Players.LocalPlayer.Character:GetChildren() do if tool:IsA("Tool") or tool:IsA("HopperBin") then numTools = numTools + 1 if numTools > maxTools then tool:Destroy() end end end end)
-The [Guy] |
|
|
| Report Abuse |
|
|