Drag dead people tool does not seem to work

I decided to make a drag dead people tool which has the ragdoll death script with it however
whenever I click on the player to drag them I get this message:

Dragger (The ServerSript), Line 5: Torso is not a valid member of Player

I am using an event and using a rope to drag for this so here are the scripts:

The LocalScript (“Get”)

function getMouseTarget()

local cursorPosition = game:GetService("UserInputService"):GetMouseLocation()

local oray = game.workspace.CurrentCamera:ViewportPointToRay(cursorPosition.x, cursorPosition.y, 0)

local ray = Ray.new(game.Workspace.CurrentCamera.CFrame.p,(oray.Direction * 1000))

return workspace:FindPartOnRay(ray)

end

script.Parent.Activated:Connect(function(mouse)

local part, mousepos = getMouseTarget()

if part.Parent.Humanoid.Health <= 0 then

local plrClick = part.Parent

script.Parent.DragPlr:FireServer(game.Players.LocalPlayer.Character.Name, plrClick.Parent.Name)

end

end)

The ServerScript (“Dragger”)

script.Parent.OnServerEvent:Connect(function(plr1, plr2)

print(plr2)

local rope = Instance.new("RopeConstraint", workspace)

local at0 = workspace[plr2].Torso:FindFirstChild("Attachment")

local at1 = plr1.Torso:WaitForChild("BodyFrontAttachment")

rope.Attachment0 = at0

rope.Attachment1 = at1

end)

Why does it give me the error?

Note: I don’t know why there is a space before and after every line in the code. It wasn’t like that when I scripted it.

You’re trying to get the torso from the player instance instead of their character. I’m assuming you’re using R6 since R15 uses upper/lower torso. Maybe you could try:

local at1 = plr1.Character.Torso:WaitForChild("BodyFrontAttachment")

Also,

You don’t need to send the local player’s name over to the server, since the first argument to OnServerEvent is the player who fired that event. This means that plr1 is the player who fired the event and plr2 is the name of the local player, while the name of the second player doesn’t get handled by the server.

2 Likes

Thanks for the post, this might help, I am gonna test it right now

Ok so now I get this:

Workspace is not a valid member of Workspace
(Line 4 of Dragger)

Here is the new code:

script.Parent.OnServerEvent:Connect(function(player, player2)
	print(player2)
	local rope = Instance.new("RopeConstraint", workspace)
	local at0 = workspace[player2].Torso:FindFirstChild("Attachment")
	local at1 = player.Torso:WaitForChild("BodyFrontAttachment")
	rope.Attachment0 = at0
	rope.Attachment1 = at1
end)

Player 2 prints “Workspace”

However it checks if the player has no health and goes to the clicked object’s parent which is MrOofBoyPlayz (Or the characters name)

Try removing the “workspace” before the “[player2]” maybe? That’s probably why it tries to locate another Workspace.

But it should find the character’s model in workspace using there name?

“Workspace is not a valid member of Workspace” You should use Character.Torso instead.

Aha! We are on to something, it says it is attempting to index nil with find first child on line 4 of dragger, here is the code:

script.Parent.OnServerEvent:Connect(function(player, player2)
	print(player2)
	local rope = Instance.new("RopeConstraint", workspace)
	local at0 = player2.Torso:FindFirstChild("Attachment")
	local at1 = player.Character.Torso:WaitForChild("BodyFrontAttachment")
	rope.Attachment0 = at0
	rope.Attachment1 = at1
end)

Oh ok, I will try that too.

Thanks so much! I edited the localScript to this and it works!

function getMouseTarget()
	local cursorPosition = game:GetService("UserInputService"):GetMouseLocation()
	local oray = game.workspace.CurrentCamera:ViewportPointToRay(cursorPosition.x, cursorPosition.y, 0)
	local ray = Ray.new(game.Workspace.CurrentCamera.CFrame.p,(oray.Direction * 1000))
	return workspace:FindPartOnRay(ray)
end

script.Parent.Activated:Connect(function(mouse)
local part, mousepos = getMouseTarget()
	if part.Parent.Humanoid.Health <= 0 then
		local plrClick = game.Players:GetPlayerFromCharacter(part.Parent)
		script.Parent.DragPlr:FireServer(plrClick)
	end
end)