So the script is supposed to clone a drag detector PlayerDrag from Server Storage and insert it into a player’s character torso after they die, but it only works once and doesn’t work again I don’t really know what the issue is or how to fix it, so please help if you’re able to and thanks
Here is the code:
game.Players.PlayerAdded:Connect(function(plyr)
local char = plyr.Character or plyr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local drag = game.ServerStorage.PlayerDrag
hum.Died:Connect(function()
local Part = drag:Clone()
Part.Parent = char.Torso
end)
end)
That’s probably because you don’t have a CharacterAdded event setup, so it only runs once.
local function onCharacterAdded(char)
local hum = char:WaitForChild("Humanoid")
local drag = game.ServerStorage.PlayerDrag
hum.Died:Connect(function()
local Part = drag:Clone()
Part.Parent = char.Torso
end)
end
game.Players.PlayerAdded:Connect(function(plyr)
if plyr.Character then
onCharacterAdded(plyr.Character)
end
plyr.CharacterAdded:Connect(onCharacterAdded)
end)
I’m not at my computer so I can’t test anything, but try removing the onCharacterAdded function and just keep the “died” function (I’m new to scripting so it might not work)