What I'm trying to make this script do is when a player killed a test dummy. The item from the test dummy will drop on the ground, but the tool is in lighting though not in the test dummy and if the player don't pick up that item, then it will be remove in a certain amount of time. How can I do that? Can somebody help me?
function Drop() local drops = {"Item"} local G = math.random(1, 1) local Obj = game.Lighting:findFirstChild(drops[G]):Clone() Obj.Parent = game.Workspace -- Obj.Handle.CFrame = script.Parent.Head.CFrame + Vector3.new(5,2,0) script:remove() end while true do wait(.1) if (script.Parent.Humanoid.Health <1) then Drop() end end
For your main script:
local s = game.ReplicatedStorage:FindFirstChild("DummyToolHandler"):Clone() s.Parent = Obj
For the "DummyToolHandler" script:
Make a script called "DummyToolHandler". It should be in ReplicatedStorage (I recommend this for everything you want to keep out of the game unless moved, better than Lighting). This is it's code.
Note: This script will make the tool get deleted if dropped by the player, or anytime it's parent is not Backpack or the parent does not have a child named HumanoidRootPart, after the countdown of 5 seconds.
local tool = script.Parent local maxNum = 5 local num = 0 local parent = tool.Parent local find = tool.Parent:FindFirstChild("HumanoidRootPart") local enabled = true while enabled == true do while tool.Parent ~= "Backpack" or not find do wait(1) num = num + 1 end tool.AncestryChanged:connect(function(child, par) if parent ~= par and child == tool then enabled = true end end) repeat wait() until num == 5 if tool.Parent ~= "Backpack" or not find then tool:remove() else num = 0 enabled = false end wait() end
Hopefully this worked :P Sometimes repeat wait() until --code1 == --code2 doesn't work...