Hi, i am making a spring constraint attach from a player to wherever the mouse is looking at, then destroying itself when the mouse button is let go. it works, except it only works one time, then it gives me this weird error:
The Parent property of SpringConstraint is locked, current parent: NULL, new parent -My user-
Any help? Heres the code:
local Rope = Instance.new("SpringConstraint")
game.ReplicatedStorage.CreatePart.OnServerEvent:Connect(function(player, part, mousepos, isholdingdown)
if isholdingdown == false then
Rope:Destroy()
elseif isholdingdown == true then
local A0 = Instance.new('Attachment')
local A1 = Instance.new('Attachment')
A0.Parent = workspace.Terrain
A0.WorldPosition = mousepos
A1.Parent = player.Character.HumanoidRootPart
Rope.Attachment0 = A0
Rope.Attachment1 = A1
Rope.Parent = player.Character --Error on this line
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 * 26
BV.MaxForce = Vector3.new(1000000,0,1000000)
end)
BV.Parent = char.HumanoidRootPart
end
end)
2 Likes
I assume it’s cause you’re deleting the rope and never replacing it, this will probably break your script even when you fix this error
Anyway, this should fix it, I think.
if isholdingdown == false and Rope.Parent then
Rope:Destroy()
edit: you’ll also have to also make a new Rope springconstraint whenever they do enable it
2 Likes
Still gives the same error. Heres the script you modified and see if I am doing it wrong. Im not sure:
local Rope = Instance.new("SpringConstraint")
game.ReplicatedStorage.CreatePart.OnServerEvent:Connect(function(player, part, mousepos, isholdingdown)
if isholdingdown == false and Rope.Parent then
Rope:Destroy()
return
elseif isholdingdown == true then
local A0 = Instance.new('Attachment')
local A1 = Instance.new('Attachment')
A0.Parent = workspace.Terrain
A0.WorldPosition = 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 * 26
BV.MaxForce = Vector3.new(1000000,0,1000000)
end)
BV.Parent = char.HumanoidRootPart
end
end)
1 Like
This seems to work for me in studio
local Rope = Instance.new("SpringConstraint")
game.ReplicatedStorage.CreatePart.OnServerEvent:Connect(function(player, part, mousepos, isholdingdown)
if isholdingdown == false then
Rope:Destroy()
elseif isholdingdown == true then
local A0 = Instance.new('Attachment')
local A1 = Instance.new('Attachment')
A0.Parent = workspace.Terrain
A0.WorldPosition = mousepos
A1.Parent = player.Character.HumanoidRootPart
Rope = Instance.new("SpringConstraint")
Rope.Attachment0 = A0
Rope.Attachment1 = A1
Rope.Parent = player.Character --Error on this line
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 * 26
BV.MaxForce = Vector3.new(1000000,0,1000000)
end)
BV.Parent = char.HumanoidRootPart
end
end)
I made my edit obvious so you know what I did
2 Likes
thanks so much for helping me
2 Likes
no problem, have a nice day
I used an old version of your script for my test, so you may want to add the return thing again
3 Likes