game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
wait()
player.Character:WaitForChild("Humanoid").Died:Connect(function()
for i,v in pairs(player.Backpack:GetChildren()) do
v.Parent = workspace
v:MoveTo(player.Character:GetPrimaryPartCFrame().p)
end
for i,v in pairs(player.Character:GetChildren()) do
if v:IsA("Tool") then
v.Parent = workspace
v:MoveTo(player.Character:GetPrimaryPartCFrame().p)
end
end
end)
end)
end)
tell me if i got anything wrong, this was made in the websites script editor
You can use the :GetChildren() function, and then run a for loop that iterates through each child (GetChildren function returns a table) of the Backpack and drops it.
Edit: You’d probably have to set the CFrame of the handle to a position near the character, as well. This post could help you with that.
player.CharacterAdded:Connect(function()
wait()
player.Character:WaitForChild("Humanoid").Died:Connect(function()
for i,v in pairs(player.Backpack:GetChildren()) do
v.Parent = workspace
v.Handle.Anchored = true
v.Handle.CanCollide = true
v.Handle.CFrame = CFrame.new(player.Character.PrimaryPart.CFrame * Vector3.new(math.random(1,5),3,3))
wait(0.2)
v.Handle.Anchored = false
end
for i,v in pairs(player.Character:GetChildren()) do
if v:IsA("Tool") then
v.Parent = workspace
v.Handle.CanCollide = true
v.Handle.CFrame = CFrame.new(player.Character.PrimaryPart.CFrame * Vector3.new(math.random(1,5),3,3))
wait(0.2)
v.Handle.Anchored = false
end
end
end)
end)
end)```
It works but i got another problem. When the player dies… Character Parts touches the tool and the same thing happens. Would there be a way to make the tool drop 10-20 studs away from the player?
You could create a seperate script which regularly deletes all objects found in the workspace with a ClassName == “Tool”.
(I imagine this information is probably useless to you by now, but I’d rather post it for anyone who happens to be interested after scrolling through this thread.)
good idea, but better is to create a function and wait 30 seconds and then remove the tools, you can use Task.wait or Task.Delay you see. edit: it is better to do it in the script itself to know which tools have not been grabbed in an optimized way.