Fixing a rope constraint made by a script

Currently this happens:

However, I want it to be more like a laser head-shotting them.

How would I do so?

Code (In case needed):

script.Parent.DetectionPart.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		local character = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		if not player.TeamColor ~= BrickColor.new("Bright red") then
			local rope = Instance.new("RopeConstraint", script.Parent)
			rope.Color = BrickColor.new("Deep blue")
			rope.Thickness = .08
			
			local attachment0 = Instance.new("Attachment", character.Head)
			
			rope.Attachment0 = attachment0
			rope.Attachment1 = script.Parent.Shotpart.Attachment1
			rope.Visible = true
			wait(.2)
			character.Humanoid.Health = 0
			rope:Destroy()
			attachment0:Destroy()
		end
	end
end)

Are you string to make a laser? Not something that pulls the player?

Yeah. I was going to use a beam but it wasn’t cylindrical.

Use a part for this. Make a cylindrical part and set the cframe to be looking at it

Why exactly are you using a Rope as a laser…

All I know is that you should use another part that’s anchored instead of the head. Ropes are for pulling.

Another option is creating a Part.

How would a part work though. I need to be able to position each end so one end is on the laser’s tip and another on the players head.

Let me write something out give me 1 second

I’ve done this many times but I think he’s got it.

To set the part cframe use something like this

CFrame.new(StartPosition,EndPosition) * CFrame.new(0,0,-Distance/2) * CFrame.Angles(0,math.rad(90),0)

You may not need the CFrame.Angles depending on what type of part you are using
And set the size of the part to the magnitude between the start and end position

StartPosition would be the tip of the laser and end position would be the player’s head, correct?

1 Like

I would use CFrame.lookAt if I were you…

No. This will not work on some parts including a cylindrical part

I believe that is correct. But also, you’ll need to set the X size of the part to (StartPosition-EndPosition).Magnitude

Yeah i mentioned that in the post

CFrame.new was replaced by CFrame.lookAt. They have the same functionality, and the 3rd argument is optional.

So should I use CFrame.new or CFrame.lookAt?

You’re good to go if you use CFrame.lookAt. I believe CFrame.new(start,end) is deprecated, as the documentation site says to use CFrame.lookAt instead.

Ok. So how would I set the size of the cylinder since depending on the distance of the character the size will change.

Part.Size = Vector3.new((startpos-endpos).Magnitude, 0.25, 0.25)
That will work I believe.

Did I use this correctly?

part.Position = CFrame.lookAt(character.Head.Position)