SeranokJoin Date: 2009-12-12 Post Count: 11083 |
When the user presses backspace, I want to remove the currently equipped gear if any.
First I tried this:
player:GetMouse().KeyDown:connect(function(key)
if string.byte(key) == 8 then
-- backspace key was pressed
for _, child in pairs(player.Character:GetChildren()) do
if child.ClassName == "Tool" then
child:Destroy()
end
end
end
end)
But that didn't work because the tool had already been moved by the time my listener was called. I could do this:
player.Backpack.ChildRemoved:connect(function(child)
wait()
if child.Parent == Workspace then
child:Destroy()
end
end)
Are there any better solutions, preferably that don't use wait or tick? |
|
BJDyerJoin Date: 2011-11-28 Post Count: 6961 |
That's the only one I know.
Technically I should have 18k posts and i'm BD/Gatorfan1 |
|
eJorgeJoin Date: 2011-06-09 Post Count: 5966 |
Why don't you use a ChildAdded event on workspace?
workspace.ChildAdded:connect(function(child)
if child:IsA("Tool") then
child:Destroy()
end
end) |
|
belial52Join Date: 2009-10-10 Post Count: 8074 |
Actually, your second one would only fire once and wouldn't remove it once it entered the workspace simply because tools are removed from your backpack and put into your character when you use them. |
|
UnAdminJoin Date: 2012-07-10 Post Count: 4706 |
Is Scripting Helpers down?
~I love to trade! Send me trade requests!~ |
|
rcmJoin Date: 2008-07-29 Post Count: 621 |
Why not just set the .CanBeDropped property to false? |
|
SeranokJoin Date: 2009-12-12 Post Count: 11083 |
> Why not just set the .CanBeDropped property to false?
Because then the tool is moved to the backpack, instead of being removed altogether. |
|
VoidacityJoin Date: 2009-11-05 Post Count: 15759 |
[ Content Deleted ] |
|
|
workspace.ChildAdded:connect(function(x)
if x:IsA("Tool") or x:IsA("HopperBin") then
x:Destroy()
end
end) |
|
|
game.Players.PlayerAdded:connect(function(plyr)
plyr.CharacterAdded:connect(function(char)
char.ChildAdded:connect(function(child)
if child:IsA("Tool") then
plyr:GetMouse().KeyDown:connect(function(key)
if key:byte() == 8 and child and plyr.Backpack:FindFirstChild(child.Name) then
child:Destroy()
end
end)
end
end)
end)
end)
Something like that? |
|
iiWishezJoin Date: 2012-07-19 Post Count: 17 |
thanks your script worked for me c: FreeToTake |
|
XML1Join Date: 2013-06-26 Post Count: 95 |
I don't know if you consider this hacky but use a hopperbin and weld anything to the player for the tool part. (unless you need tool-specific methods, hopperbins are the best because they stay selected when you press backspack) |
|
|
Set CanBeDropped to false and use a modified version of your first example? |
|