local event=game.ReplicatedStorage:WaitForChild("WebSpawn")
local event2=game.ReplicatedStorage:WaitForChild("WebLength")
event.OnServerEvent:Connect(function(player, attachment, pos, canShoot, ropeObj)
if canShoot.Value==true then --if player can shoot
canShoot.Value=false
--setting up the rope
local rope=Instance.new("RopeConstraint")
rope.Thickness = 0.2
rope.Restitution=0.8
rope.Color = BrickColor.new("White")
rope.Visible=true;
rope.Enabled=false
ropeObj.Value=rope
local attachment0 = attachment
local attachment1 = Instance.new("Attachment")
rope.Attachment0 = attachment0
rope.Attachment1 = attachment1
rope.Parent = workspace.Terrain
attachment1.Parent = workspace.Terrain
attachment1.Position = pos
local magnitude = (attachment0.Position - attachment0.Position).Magnitude
if magnitude<300 then
rope.Length=magnitude
wait()
rope.Enabled=true
while rope.Length>1 and rope.Enabled do
wait()
end
end
rope:Destroy();
wait(1)
canShoot.Value=true
end
end)
So I immediately notice you are subtracting attachment0 from attachment0, which would equate to 0. Secondly, if the magnitude is over 300, it will never successfully run the desired code.
Yes at first i used two variables (start and finish) to store the positions and i realized before posting that they are useless, i edited and that’s when i made the mistakes.
now i have like this, but it still doesn’t seem to work
local magnitude = math.abs((attachment0.Position - attachment1.Position).Magnitude)
The magnitude of a vector is the length of that vector. If you think of a vector as an arrow, then the magnitude of the vector is the length of the arrow. Geometrically, it doesn’t make sense for an arrow to have negative length — what would an arrow like that look like? Therefore, the length of an arrow — and likewise the magnitude of a vector — is always positive.
When you subtract two vectors, you get another vector. All vectors have a magnitude and a direction. Regardless of whether the magnitude of attachment1.Position is bigger or smaller than the other attachment, the resulting vector will have its own magnitude which is positive.