Can't define torso under player in workspace(R6)

I am creating a system in which when one part is clicked, a second part moves to a position in which it is behind the player no matter where they click the part from

This works, but it would only work for me because my script finds the first child by my username

local part = game.Workspace.ClickPart
local brick = script.Parent

part.ClickDetector.MouseClick:Connect(function(hit)
	local Torso = game.Workspace:FindFirstChild("tnouf2").Torso
	brick.Position = Torso.Position - Torso.CFrame.lookVector + Vector3.new(0,0,-3)
end)

(script is inside of the part that spawns behind you)

Does anybody know how to make line 5 work for any player, and not just myself?

1 Like

Argument that is passed to your anonymous function is actual player that has clicked.

part.ClickDetector.MouseClick:Connect(function(player)
    local torso = player.Character:FindFirstChild("Torso")
    brick.Position = torso.Position - torso.CFrame.LookVector + Vector3.new(0,0,-3)
end)
2 Likes

This error comes up
Workspace.Part.Script:6: attempt to index nil with ‘Position’

Nevermind, I found the issue, thank you

1 Like