Hi, is there any way to know if a player drop a tool? like when i drop a sword it says in output “Dropped”
Any help is welcome!
have a good day
Hi, is there any way to know if a player drop a tool? like when i drop a sword it says in output “Dropped”
Any help is welcome!
have a good day
You could check if a Child was removed from the Character since when you equip a tool it’s placed into your character. And then, check if the child is in the backpack and if it isn’t, assume it was dropped
workspace.ChildAdded:Connect(function(item)
if item:IsA("Tool") then
if not item.Parent:IsA("Model") and game.Players:GetPlayerFromCharacter(item.Parent) then
-- now you know the tool was dropped
end
end
end
Hello
I have a question
When the location of the item changes, so does the parent
Next, how does your code want to check that the item has been dropped from the player?
(I just want it added to my info! )
Sorry I’m A bit late but here is a script I made which goes in the tool and can detect who drops a tool, when It is dropped, who picked it up, and when it is picked up.
local Dropped = false
local ToolParent = script.Parent.Parent
local LastPlayer = game:GetService("Players"):GetPlayerFromCharacter(ToolParent) -- change to nil of ya feel it fits better. it doesn't matter much cause both LastPlayer and CurrentPlayer start as nil
local CurrentPlayer = game:GetService("Players"):GetPlayerFromCharacter(ToolParent)
script.Parent.AncestryChanged:Connect(function(child,parent)
LastPlayer = game:GetService("Players"):GetPlayerFromCharacter(ToolParent)
ToolParent = script.Parent.Parent
CurrentPlayer = game:GetService("Players"):GetPlayerFromCharacter(ToolParent)
if parent:IsA("Workspace") then
Dropped = true
print("dropped")
-- insert code here
else
if Dropped == true then
Dropped = false
print("picked up")
-- insert code here
end
end
print(LastPlayer)
print(CurrentPlayer)
end)
also here is a version that shows the last person to hold the tool before it was dropped when picked up.
local Dropped = false
local ToolParent = script.Parent.Parent
local LastPlayer = game:GetService("Players"):GetPlayerFromCharacter(ToolParent) -- change to nil of ya feel it fits better. it doesn't matter much cause both LastPlayer and CurrentPlayer start as nil
local CurrentPlayer = game:GetService("Players"):GetPlayerFromCharacter(ToolParent)
local PlayerBeforeLast = LastPlayer
script.Parent.AncestryChanged:Connect(function(child,parent)
PlayerBeforeLast = LastPlayer
LastPlayer = game:GetService("Players"):GetPlayerFromCharacter(ToolParent)
ToolParent = script.Parent.Parent
CurrentPlayer = game:GetService("Players"):GetPlayerFromCharacter(ToolParent)
if parent:IsA("Workspace") then
Dropped = true
print("dropped")
-- insert code here
else
if Dropped == true then
Dropped = false
print("picked up")
-- insert code here
end
end
print(PlayerBeforeLast)
print(LastPlayer)
print(CurrentPlayer)
end)
You can add a queue of as many previous players as you want by merely stacking the variables onto the next player who owned the tool. An example of this would be that if i wanted the object parent before the “PlayerBeforeLast” variable then I could add a new variable for the object and set that variable to equal the “PlayerBeforeLast” variable before the “PlayerBeforeLast” variable changes.
Also, Here is another script which can be used to get every parent to ever own the tool. Note: This Table only holds previous Parents not the current one and it does not show when there are non-player owners. If you want to make it show no owner it might be a bit more work.
local Dropped = false
local ToolParent = script.Parent.Parent
local LastPlayer = game:GetService("Players"):GetPlayerFromCharacter(ToolParent) -- change to nil of ya feel it fits better. it doesn't matter much cause both LastPlayer and CurrentPlayer start as nil
local CurrentPlayer = game:GetService("Players"):GetPlayerFromCharacter(ToolParent)
local PlayerBeforeLast = LastPlayer
local PreviousOwners = {}
script.Parent.AncestryChanged:Connect(function(child,parent)
PlayerBeforeLast = LastPlayer -- sets the player before the last player variabl
LastPlayer = game:GetService("Players"):GetPlayerFromCharacter(ToolParent) -- sets the last player variable
table.insert(PreviousOwners,LastPlayer) -- adds the last player to the previous owner queue
ToolParent = script.Parent.Parent -- updates the tool parent variable to the current tool parent
CurrentPlayer = game:GetService("Players"):GetPlayerFromCharacter(ToolParent) -- sets the current player variable
if parent:IsA("Workspace") then
Dropped = true -- the tool is currently dropped so set the dropped variable to true
print("dropped")
-- insert code here
else
if Dropped == true then
Dropped = false -- the tool is not currently dropped so set the dropped variable to false
print("picked up")
-- insert code here
end
end
print(PreviousOwners)
print(PlayerBeforeLast)
print(LastPlayer)
print(CurrentPlayer)
end)
also, yes, I have gone a bit overboard on this.
edit: also, idk how Gotee’s script worked cause it detects when an object is added to the workspace and then cancels it out in the script with this: game.Players:GetPlayerFromCharacter(item.Parent)
which will always return nil when inside of that function because the object’s parent will always be the workspace there. An easier non over-complicated version of it would just be:
workspace.ChildAdded:Connect(function(item)
if item:IsA("Tool") then
-- item was dropped
end
end
.ChildAdded
detects when a child is added to a workspace, not a descendant so there is no need to detect what the parent is. it is possible that they got confused between .ChildAdded
and .DescendantAdded
but even so it still wouldn’t work because the if statement
“if not item.Parent:IsA("Model") and game.Players:GetPlayerFromCharacter(item.Parent) then
”
will always cancel itself out and not work. this statement basically says “if item is not a model and item is a model then
”.
Sorry for my rant. Just stating the obvious here.