How should i convert this to a clickdetector?


grabbed = false
currentPlayer = ""
part = script.Parent.Parent


script.Parent.Triggered:Connect(function(player)
	
	
	if grabbed == false then
		
		currentPlayer = player.Name
		
		local head = player.Character.Head
		local x = head.CFrame.X
		local y = head.CFrame.Y
		local z = head.CFrame.Z
		
		
		part.CFrame = CFrame.new(x,y,z)
		part.CFrame = part.CFrame + head.CFrame.LookVector * 4
		
		part.Massless = true
		
		
		grip = Instance.new("WeldConstraint")
		grip.Part0 = head
		grip.Part1 = part
		grip.Parent = head
		
		
		script.Parent.ActionText = "Drop"
		part.CanCollide = false
		
		
		grabbed = true
		
		
		-- DROP --
	else
		
		if player.Name == currentPlayer then
			grip:Remove()
			currentPlayer = ""
			part.Massless = false
			part.CanCollide = true
			
			script.Parent.ActionText = "Pick Up"
			
			grabbed = false
		end
	end
end)

this is a script for picking things up, through a proximity prompt, i’m wondering, how should i convert this script to work upon clicking something by clickdetector instead?

script.Parent.MouseClick:Connect(function()

end)

1 Like
grabbed = false
currentPlayer = ""
part = script.Parent.Parent

local clickDetector = script.Parent.ClickDetector

clickDetector.MouseClick:Connect(function(player)

  if grabbed == false then

    currentPlayer = player.Name

    local head = player.Character.Head
    local x = head.CFrame.X
    local y = head.CFrame.Y
    local z = head.CFrame.Z

    part.CFrame = CFrame.new(x, y, z)
    part.CFrame = part.CFrame + head.CFrame.LookVector * 4

    part.Massless = true

    grip = Instance.new("WeldConstraint")
    grip.Part0 = head
    grip.Part1 = part
    grip.Parent = head

    script.Parent.ActionText = "Drop"
    part.CanCollide = false

    grabbed = true

  else

    if player.Name == currentPlayer then
      grip:Remove()
      currentPlayer = ""
      part.Massless = false
      part.CanCollide = true

      script.Parent.ActionText = "Pick Up"

      grabbed = false
    end
  end
end)

you think is it working about it?