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.
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)