Items wont drop on death

local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Death1 = ReplicatedStorage.Animations.Death1
local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")
local HumanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local ToolDropOnDeath = ReplicatedStorage.RemoteEvents.ToolDropOnDeath

local deathanimtrack
humanoid.HealthChanged:Connect(function()
	if humanoid.Health <= 0 then
		
		humanoid:UnequipTools()

		ToolDropOnDeath:FireServer()

		HumanoidRootPart.Massless = true
		deathanimtrack = humanoid:LoadAnimation(Death1)
		deathanimtrack:Play()
		wait(2)
		HumanoidRootPart.Massless = false

	end
end)

server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ToolDropOnDeath = ReplicatedStorage.RemoteEvents.ToolDropOnDeath

ToolDropOnDeath.OnServerEvent:Connect(function(player)
	local HumanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
	
	for i,tool in pairs(player.Backpack:GetChildren()) do
		if tool:IsA("Tool") and tool:FindFirstChild("Handle") then	
			tool.Parent = game.Workspace
			tool.Handle.CFrame = HumanoidRootPart.CFrame
		end
	end
	
end)
2 Likes

Make sure that the tool is CanCollide == true after setting his parent to Workspace. If CanCollide will be false then tool will fall out of the map.

1 Like

https://gyazo.com/eec023ff45efe00a73201f156fd41821
what if the tools stay in the backpack

1 Like

Let me give a minute, I will try to figure out how to fix it

1 Like

Can u show me how the backpack looks after you run the script?

1 Like

https://gyazo.com/4b857b7a17c9c58f5b8450727b7cd685

Why not use the Humanoid.Died event?

Humanoid.Died:Connect(function()
    --fires whenever the player dies
end)

well the death animations play so i dont think thats the problem

Try to remove :GetChilden()
for i, v in pairs should automically get all childrens from the object

ServerScriptService.DropTools:7: invalid argument #1 to ‘pairs’ (table expected, got Instance)

ex dee

1 Like

Well, it’s better than detecting it when it changes AND you can even do this also:

-- Server script in StarterCharacter
local Character = script.Parent
local player = game.Players:GetPlayerFromCharacter(Character)
local humanoid = Character:WaitForChild("Humanoid")
local humanoidRoot = Character:WaitForChild("HumanoidRootPart")
local deathanimtrack

humanoid.Died:Connect(function()
     humanoid:UnequipTools()
     for I, tools in pairs(player.Backpack:GetChildren()) do
         tools.Parent = workspace
     end
     humanoidRoot.Massless = true
     deathanimtrack = humanoid:LoadAnimation(Death1) --where is this?
     deathanimtrack:Play()
     wait(2)
     humanoidRoot.Massless = false
end)

This could be used, no remote events were necessary, quite easier.

1 Like

Ah yes, :GetChildren() is not the problem

1 Like

When the player equips a tool, it gets cloned into the Character. Try looping through their character for any tools. If not try their starterpack.

Yes because they are using UserInputService which is local. This can be handled on the server.

Wait, why did you link the reply?

i used humanoid:UnequipTools() before i parented the tools to game.workspace

do you know wat filtering enabled is

1 Like

You should make this on Server-Side because exploiters can bypass it.

1 Like

Yes, I know what Filtering Enabled is.

1 Like

what do u mean by server-side, how would i detect a players death?

1 Like