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
 

Re: How do you remove a player's tools when they touch a brick

Previous Thread :: Next Thread 
Weirdraidercs35 is not online. Weirdraidercs35
Joined: 14 May 2015
Total Posts: 2275
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
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
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
Weirdraidercs35 is not online. Weirdraidercs35
Joined: 14 May 2015
Total Posts: 2275
07 Oct 2015 01:23 AM
okey ill try it
Report Abuse
Weirdraidercs35 is not online. Weirdraidercs35
Joined: 14 May 2015
Total Posts: 2275
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
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
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
Weirdraidercs35 is not online. Weirdraidercs35
Joined: 14 May 2015
Total Posts: 2275
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 is not online. 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
Weirdraidercs35 is not online. Weirdraidercs35
Joined: 14 May 2015
Total Posts: 2275
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
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
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
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
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
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