Attachment to mouse

Hi, I want to make a spring attachment from the players position to wherever the mouse is. It keeps giving me this error:
invalid argument #3 (Instance expected, got number)

Can anyone help? This is my current script:

--// Local script inside StarterGUI (irrelevant but here if anyone asks) \\

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Move:Connect(function()
	local target = mouse.Target
	if not target then
		mouse.Icon = 'http://www.roblox.com/asset/?id=591711615'
	else
		if target:IsA("BasePart") or target:IsA("Model") then 
			if target == workspace.Base or target == workspace.Base2 or target.Parent == workspace.Map then 
				if target.Parent == workspace then
					mouse.Icon = 'http://www.roblox.com/asset/?id=6888146193'
					if mouse.Icon == 'http://www.roblox.com/asset/?id=6888146193' then
						mouse.Button1Down:Connect(function()
							game.ReplicatedStorage.CreatePart:FireServer(target, mouse.Hit)
						end)
					end
				else 
					mouse.Icon = 'http://www.roblox.com/asset/?id=6888146193'
					if mouse.Icon == 'http://www.roblox.com/asset/?id=6888146193' then
						mouse.Button1Down:Connect(function()
							game.ReplicatedStorage.CreatePart:FireServer(target, mouse.Hit)
						end)
					end
				end
			else
				mouse.Icon = 'http://www.roblox.com/asset/?id=591711615' 
			end
		end
	end
end)


--// Server Script inside ServerScriptService (where the error is) \\

local ropeismade = false
local Rope = Instance.new("SpringConstraint")

game.ReplicatedStorage.CreatePart.OnServerEvent:Connect(function(player, part, mousepos)	
	if ropeismade == true then
		return
	elseif ropeismade == false then
		local A0 = Instance.new('Attachment')
		local A1 = Instance.new('Attachment')
		ropeismade = true
		A0.Parent = mousepos --Error on this line
		A1.Parent = player.Character.HumanoidRootPart
		Rope.Attachment0 = A0
		Rope.Attachment1 = A1
		Rope.Parent = player.Character
		Rope.Visible = true
		Rope.LimitsEnabled = true
		Rope.Coils = 0
		Rope.Thickness = 0.1
		Rope.Color = BrickColor.new("Institutional white")
		Rope.MaxLength = (player.Character.HumanoidRootPart.Position - part.Position).Magnitude
		local BV = Instance.new('BodyVelocity')
		local char = player.Character
		char:WaitForChild("Humanoid"):GetPropertyChangedSignal("MoveDirection"):Connect(function()
			BV.Velocity = player.Character.Humanoid.MoveDirection * 25
			BV.MaxForce = Vector3.new(1000000,0,1000000)
		end)
		BV.Parent = char.HumanoidRootPart
	end
end)
1 Like

I think your mistake is on the fact that you are parenting the attachment 0 to some CFrame?

Try modifiyng the server script as follows:

local ropeismade = false
local Rope = Instance.new("SpringConstraint")

game.ReplicatedStorage.CreatePart.OnServerEvent:Connect(function(player, part, mousepos)	
	if ropeismade == true then
		return
	elseif ropeismade == false then
		local A0 = Instance.new('Attachment')
		local A1 = Instance.new('Attachment')
		ropeismade = true
        -- changed here:
		A0.Parent = workspace.Terrain
        A0.WorldCFrame = mousepos

		A1.Parent = player.Character.HumanoidRootPart
		Rope.Attachment0 = A0
		Rope.Attachment1 = A1
		Rope.Parent = player.Character
		Rope.Visible = true
		Rope.LimitsEnabled = true
		Rope.Coils = 0
		Rope.Thickness = 0.1
		Rope.Color = BrickColor.new("Institutional white")
		Rope.MaxLength = (player.Character.HumanoidRootPart.Position - part.Position).Magnitude
		local BV = Instance.new('BodyVelocity')
		local char = player.Character
		char:WaitForChild("Humanoid"):GetPropertyChangedSignal("MoveDirection"):Connect(function()
			BV.Velocity = player.Character.Humanoid.MoveDirection * 25
			BV.MaxForce = Vector3.new(1000000,0,1000000)
		end)
		BV.Parent = char.HumanoidRootPart
	end
end)

image

Try instead of A0.WorldCFrame = mousepos to write: A0.WorldPosition = mousepos

1 Like

By the way, I looked more into your scripts, and there are some problems with your Local script as well. I would write it as follows:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local target = nil

mouse.Button1Down:Connect(function()
	game.ReplicatedStorage.CreatePart:FireServer(target, mouse.Hit)
end)

mouse.Move:Connect(function()
	target = mouse.Target
	if not target then
		mouse.Icon = 'http://www.roblox.com/asset/?id=591711615'
	else
		if target:IsA("BasePart") or target:IsA("Model") then
			if target == workspace.Base or target == workspace.Base2 or target.Parent == workspace.Map then 
				mouse.Icon = 'http://www.roblox.com/asset/?id=6888146193'
			else
				mouse.Icon = 'http://www.roblox.com/asset/?id=591711615' 
			end
		end
	end
end)

That breaks the server script world position so I think ill just keep the old one. Thanks so much though!

If it breaks the server script world position, use WorldCFrame instead.
Trust me, the new Local Script I sent you is 100% better.
Actually, the one you have in your post, is most likely going to crash after a while. You are creating and leaking a never ending amount of signals.