The Rope length < 7 runs only once instead of running every time i equip the tool

You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? for code to run again after player equipped tool

  1. What is the issue? [Screen Capture 21.07.2023, 18.25.57

  2. What solutions have you tried so far? dev hub, looking dev forum posts, adding while loop.

i want for RopeConstrait.Length < 7 code to run every time i equip the tool but it runs only once

server:

wait(game.Loaded)

--// Statements
local LMB_Remote = script.Parent.LMB_Remote
local E_Key_Remote = script.Parent.E_Key_Remote
local Q_Key_Remote = script.Parent.Q_Key_Remote

local E_Key_Connection: RBXScriptConnection = nil
local Q_Key_Connection: RBXScriptConnection = nil
local LMB_Connection: RBXScriptConnection = nil

local tool = script.Parent
	
--//Main Code
tool.Equipped:Connect(function()
	LMB_Connection = LMB_Remote.OnServerEvent:Connect(function(player, target)
		
		local Distance = (player.Character.HumanoidRootPart.Position - target.Position).Magnitude
		local Connection_Distance = 50
		local Maximum_Length = 50
		local minimumLength = 5.5
		local decrease = 0.5
		local increase = 0.5
		
		local Rope_Attached = target.Rope_Attached.Value
		
		if Rope_Attached == false and (player.Character.HumanoidRootPart.Position - target.Position).Magnitude < Connection_Distance then
			target.Rope_Attached.Value = true
			local ropeconstraint = Instance.new("RopeConstraint")
	        local attachment0 = Instance.new("Attachment")
	        local attachment1 = Instance.new("Attachment")
	        local blocks = target.Parent

			if blocks.Name == player.Name then
				
				print("Distance is "..Distance.." Connection Distance is "..Connection_Distance)
		attachment0.Parent = target
		attachment1.Parent = script.Parent.Parent.Torso
		ropeconstraint.Attachment0 = attachment0
		ropeconstraint.Attachment1 = attachment1
		ropeconstraint.Color = BrickColor.new("Black")
		ropeconstraint.Visible = true
				ropeconstraint.Parent = script.Parent.Parent.Torso
				ropeconstraint.Length = Distance
				
				if ropeconstraint.Length < minimumLength then
					ropeconstraint.Length = minimumLength
					decrease = 0
				end
				if ropeconstraint.Length < 7 then
					player.Character.Humanoid.JumpPower = 0
					decrease = 0.5
				end
				if ropeconstraint.Length > minimumLength then
					decrease = 0.5
				end

				if ropeconstraint.Length > 7 then
					player.Character.Humanoid.JumpPower = 50
					decrease = 0.5
				end
				if ropeconstraint.Length > Maximum_Length then
					increase = 0
				end
				if ropeconstraint.Length < Maximum_Length then
					increase = 0.5
				end
			end
		
			
			E_Key_Connection = E_Key_Remote.OnServerEvent:Connect(function()
				ropeconstraint.Length += increase
			end)
			
			Q_Key_Connection = Q_Key_Remote.OnServerEvent:Connect(function()
				
				
				player.Character.Torso.Anchored = true
				ropeconstraint.Length -= decrease
				wait()
				player.Character.Torso.Anchored = false
			end)
			
--//Rope length Code
			ropeconstraint.Changed:Connect(function()
				
				if ropeconstraint.Length < minimumLength then
					ropeconstraint.Length = minimumLength
					decrease = 0
				end
				if ropeconstraint.Length < 7 then
					player.Character.Humanoid.JumpPower = 0
					decrease = 0.5
				end
				if ropeconstraint.Length > minimumLength then
					decrease = 0.5
				end
				
				if ropeconstraint.Length > 6.9 then
					player.Character.Humanoid.JumpPower = 50
					decrease = 0.5
				end
				if ropeconstraint.Length > Maximum_Length then
					increase = 0
				end
				if ropeconstraint.Length < Maximum_Length then
					increase = 0.5
				end
			end)
			end
	
		--//Tool Unequipped
		tool.Unequipped:Connect(function()
			E_Key_Connection:Disconnect()
			Q_Key_Connection:Disconnect()
			LMB_Connection:Disconnect()
		end)
			end)
	end)
wait(game.Loaded)
--// Statements
local LMB_Remote = script.Parent.LMB_Remote
local E_Key_Remote = script.Parent.E_Key_Remote
local Q_Key_Remote = script.Parent.Q_Key_Remote

local E_Key_Connection: RBXScriptConnection = nil
local Q_Key_Connection: RBXScriptConnection = nil
local LMB_Connection: RBXScriptConnection = nil
local E_Key_Connection_InputEnded: RBXScriptConnection = nil
local Q_Key_Connection_InputEnded: RBXScriptConnection = nil


local tool = script.Parent

local player = game.Players.LocalPlayer

local User_Input_Service = game:GetService("UserInputService")

--// Main Code
tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if mouse.Target.Rope_Attached.Value == false then
			LMB_Remote:FireServer(mouse.Target, mouse.TargetSurface)
			end
	end)

	local function E_Key_Pressed(Input_Object, Game_Processed_Event)
		if not Game_Processed_Event then
			if Input_Object.KeyCode == Enum.KeyCode.E then
				E_Key_Remote:FireServer()
			end
		end
	end
	
	local function Q_Key_Pressed(Input_Object, Game_Processed_Event)
		if not Game_Processed_Event then
			if Input_Object.KeyCode == Enum.KeyCode.Q then
				Q_Key_Remote:FireServer()
			end
		end
	end
	
--// Connecting Functions
   E_Key_Connection = User_Input_Service.InputBegan:Connect(E_Key_Pressed)
   Q_Key_Connection = User_Input_Service.InputBegan:Connect(Q_Key_Pressed)
	
	local function E_Key_Ended(Input_Object, Game_Processed_Event)
		if not Game_Processed_Event then
			if Input_Object.KeyCode == Enum.KeyCode.E then
				E_Key_Connection:Disconnect()
			end
		end
	end

	local function Q_Key_Ended(Input_Object, Game_Processed_Event)
		if not Game_Processed_Event then
			if Input_Object.KeyCode == Enum.KeyCode.Q then
				Q_Key_Connection:Disconnect()
			end
		end
	end
	
	E_Key_Connection_InputEnded = User_Input_Service.InputEnded:Connect(E_Key_Pressed)
	Q_Key_Connection_InputEnded = User_Input_Service.InputEnded:Connect(Q_Key_Pressed)

--// Disconnecting Functions
	tool.Unequipped:Connect(function()
		E_Key_Connection:Disconnect()
		Q_Key_Connection:Disconnect()
		E_Key_Connection_InputEnded:Disconnect()
		Q_Key_Connection_InputEnded:Disconnect()
	end)
end)

You have quite a few nested event listeners in your code that are likely the cause of the problem.

I’ve done some de-nesting and a few small cleanups. I haven’t tested my changes but at a glance they look alright. Give this a try:

if not game:IsLoaded() then
	game.Loaded:Wait()
end

--// Statements
local LMB_Remote = script.Parent.LMB_Remote
local E_Key_Remote = script.Parent.E_Key_Remote
local Q_Key_Remote = script.Parent.Q_Key_Remote

local E_Key_Connection = nil
local Q_Key_Connection = nil
local LMB_Connection = nil

local tool = script.Parent

local ropeconstraint = Instance.new("RopeConstraint")
local attachment0 = Instance.new("Attachment")
local attachment1 = Instance.new("Attachment")

local Connection_Distance = 50
local Maximum_Length = 50
local minimumLength = 5.5
local decrease = 0.5
local increase = 0.5

--//Rope length Code
local function Handle_Rope_Increment()
	if ropeconstraint.Length < minimumLength then
		ropeconstraint.Length = minimumLength
		decrease = 0
	end
	if ropeconstraint.Length < 7 then
		player.Character.Humanoid.JumpPower = 0
		decrease = 0.5
	end
	if ropeconstraint.Length > minimumLength then
		decrease = 0.5
	end

	if ropeconstraint.Length > 7 then
		player.Character.Humanoid.JumpPower = 50
		decrease = 0.5
	end
	if ropeconstraint.Length > Maximum_Length then
		increase = 0
	end
	if ropeconstraint.Length < Maximum_Length then
		increase = 0.5
	end
end

--//Main Code
tool.Equipped:Connect(function()
	E_Key_Connection = E_Key_Remote.OnServerEvent:Connect(function()
		ropeconstraint.Length += increase
	end)
	
	Q_Key_Connection = Q_Key_Remote.OnServerEvent:Connect(function()
		player.Character.Torso.Anchored = true
		ropeconstraint.Length -= decrease
		wait()
		player.Character.Torso.Anchored = false
	end)

	LMB_Connection = LMB_Remote.OnServerEvent:Connect(function(player, target)
		local Distance = (player.Character.HumanoidRootPart.Position - target.Position).Magnitude
		
		local Rope_Attached = target.Rope_Attached.Value
		
		if Rope_Attached == false and (player.Character.HumanoidRootPart.Position - target.Position).Magnitude < Connection_Distance then
			target.Rope_Attached.Value = true
			local blocks = target.Parent

			if blocks.Name == player.Name then
				
				print("Distance is "..Distance.." Connection Distance is "..Connection_Distance)
				attachment0.Parent = target
				attachment1.Parent = script.Parent.Parent.Torso
				ropeconstraint.Attachment0 = attachment0
				ropeconstraint.Attachment1 = attachment1
				ropeconstraint.Color = BrickColor.new("Black")
				ropeconstraint.Visible = true
				ropeconstraint.Parent = script.Parent.Parent.Torso
				ropeconstraint.Length = Distance
				
				Handle_Rope_Increment()
			end
		end
	end)
end)

--//Tool Unequipped
tool.Unequipped:Connect(function()
	E_Key_Connection:Disconnect()
	Q_Key_Connection:Disconnect()
	LMB_Connection:Disconnect()
end)

ropeconstraint.Changed:Connect(Handle_Rope_Increment)

your doesn’t work, there is nothing in the output as well

That’s strange, maybe try removing the first three lines then? I don’t think those are necessary in a server script anyway, just wasn’t sure if you had some need of it.

now it works but lemme just fix it a bit it has some errors

it doesn’t work

The Parent property of Attachment is locked, current parent: NULL, new parent LeashBlock -

Hmm, I’m not sure exactly why that would be happening, but I realized there were a lot of references to a player in the code that no longer were valid in my changes, this should fix those. Maybe give this another try?

--// Statements
local LMB_Remote = script.Parent.LMB_Remote
local E_Key_Remote = script.Parent.E_Key_Remote
local Q_Key_Remote = script.Parent.Q_Key_Remote

local E_Key_Connection = nil
local Q_Key_Connection = nil
local LMB_Connection = nil
local Rope_Connection = nil

local tool = script.Parent
local character = nil

local ropeconstraint = Instance.new("RopeConstraint")
local attachment0 = Instance.new("Attachment")
local attachment1 = Instance.new("Attachment")

local Connection_Distance = 50
local Maximum_Length = 50
local minimumLength = 5.5
local decrease = 0.5
local increase = 0.5

--//Rope length Code
local function Handle_Rope_Increment(character)
	if ropeconstraint.Length < minimumLength then
		ropeconstraint.Length = minimumLength
		decrease = 0
	end
	if ropeconstraint.Length < 7 then
		character.Humanoid.JumpPower = 0
		decrease = 0.5
	end
	if ropeconstraint.Length > minimumLength then
		decrease = 0.5
	end

	if ropeconstraint.Length > 7 then
		player.Character.Humanoid.JumpPower = 50
		decrease = 0.5
	end
	if ropeconstraint.Length > Maximum_Length then
		increase = 0
	end
	if ropeconstraint.Length < Maximum_Length then
		increase = 0.5
	end
end

--//Main Code
tool.Equipped:Connect(function()
	character = tool.Parent
	E_Key_Connection = E_Key_Remote.OnServerEvent:Connect(function(player)
		if player.Character == character then
			ropeconstraint.Length += increase
		end
	end)
	
	Q_Key_Connection = Q_Key_Remote.OnServerEvent:Connect(function(player)
		if player.Character == character then
			character.Torso.Anchored = true
			ropeconstraint.Length -= decrease
			wait()
			character.Torso.Anchored = false
		end
	end)

	LMB_Connection = LMB_Remote.OnServerEvent:Connect(function(player, target)
		if player.Character == character then
			local Distance = (character.PrimaryPart.Position - target.Position).Magnitude
			
			local Rope_Attached = target.Rope_Attached.Value
			
			if Rope_Attached == false and (character.PrimaryPart.Position - target.Position).Magnitude < Connection_Distance then
				target.Rope_Attached.Value = true
				local blocks = target.Parent

				if blocks.Name == character.Name then
					
					print("Distance is "..Distance.." Connection Distance is "..Connection_Distance)
					attachment0.Parent = target
					attachment1.Parent = character.PrimaryPart
					ropeconstraint.Attachment0 = attachment0
					ropeconstraint.Attachment1 = attachment1
					ropeconstraint.Color = BrickColor.new("Black")
					ropeconstraint.Visible = true
					ropeconstraint.Parent = character.PrimaryPart
					ropeconstraint.Length = Distance
					
					Handle_Rope_Increment(character)
				end
			end
		end
	end)

	Rope_Connection = ropeconstraint.Changed:Connect(function()
		Handle_Rope_Increment(character)
	end)
end)

--//Tool Unequipped
tool.Unequipped:Connect(function()
	E_Key_Connection:Disconnect()
	Q_Key_Connection:Disconnect()
	LMB_Connection:Disconnect()
	Rope_Connection:Disconnect()
end)

The Parent property of Attachment is locked, current parent: NULL, new parent LeashBlock -

The issue

After i Un equip The leash this error is in output
The Parent property of Attachment is locked, current parent: NULL, new parent LeashBlock -

Is there more code than what you’ve shown here? Can you post what you have currently in this server-side script?

wait(game.Loaded)

--// Statements
local tool = script.Parent

local LMB_Remote = script.Parent.LMB_Remote
local E_Key_Remote = script.Parent.E_Key_Remote
local Q_Key_Remote = script.Parent.Q_Key_Remote

local E_Key_Connection: RBXScriptConnection = nil
local Q_Key_Connection: RBXScriptConnection = nil
local LMB_Connection: RBXScriptConnection = nil

local Connection_Distance = 50
local Maximum_Length = 50
local minimumLength = 5.5
local decrease = 0.5
local increase = 0.5

	
--//Main Code
tool.Equipped:Connect(function()
	LMB_Connection = LMB_Remote.OnServerEvent:Connect(function(player, target)
		
		local Distance = (player.Character.HumanoidRootPart.Position - target.Position).Magnitude
		
		local Rope_Attached = target.Rope_Attached.Value
		
		if Rope_Attached == false and (player.Character.HumanoidRootPart.Position - target.Position).Magnitude < Connection_Distance then
			target.Rope_Attached.Value = true
			
			local ropeconstraint = Instance.new("RopeConstraint")
	        local attachment0 = Instance.new("Attachment")
			local attachment1 = Instance.new("Attachment")
			
	        local blocks = target.Parent

			if blocks.Name == player.Name then
				
				print("Distance is "..Distance.." Connection Distance is "..Connection_Distance)
		attachment0.Parent = target
		attachment1.Parent = script.Parent.Parent.Torso
		ropeconstraint.Attachment0 = attachment0
		ropeconstraint.Attachment1 = attachment1
		ropeconstraint.Color = BrickColor.new("Black")
		ropeconstraint.Visible = true
				ropeconstraint.Parent = script.Parent.Parent.Torso
				ropeconstraint.Length = Distance
			end
		
			
			E_Key_Connection = E_Key_Remote.OnServerEvent:Connect(function()
				ropeconstraint.Length += increase
			end)
			
			Q_Key_Connection = Q_Key_Remote.OnServerEvent:Connect(function()
				
				
				player.Character.Torso.Anchored = true
				ropeconstraint.Length -= decrease
				wait()
				player.Character.Torso.Anchored = false
			end)
			
			end
	
		--//Tool Unequipped
		tool.Unequipped:Connect(function()
			E_Key_Connection:Disconnect()
			Q_Key_Connection:Disconnect()
			LMB_Connection:Disconnect()
		end)
			end)
	end)

This is not the code I sent you.

--// Statements
local LMB_Remote = script.Parent.LMB_Remote
local E_Key_Remote = script.Parent.E_Key_Remote
local Q_Key_Remote = script.Parent.Q_Key_Remote

local E_Key_Connection = nil
local Q_Key_Connection = nil
local LMB_Connection = nil
local Rope_Connection = nil

local tool = script.Parent
local character = nil

local ropeconstraint = Instance.new("RopeConstraint")
local attachment0 = Instance.new("Attachment")
local attachment1 = Instance.new("Attachment")

local Connection_Distance = 50
local Maximum_Length = 50
local minimumLength = 5.5
local decrease = 0.5
local increase = 0.5

--//Rope length Code
local function Handle_Rope_Increment(character)
	if ropeconstraint.Length < minimumLength then
		ropeconstraint.Length = minimumLength
		decrease = 0
	end
	if ropeconstraint.Length < 7 then
		character.Humanoid.JumpPower = 0
		decrease = 0.5
	end
	if ropeconstraint.Length > minimumLength then
		decrease = 0.5
	end

	if ropeconstraint.Length > 7 then
		character.Humanoid.JumpPower = 50
		decrease = 0.5
	end
	if ropeconstraint.Length > Maximum_Length then
		increase = 0
	end
	if ropeconstraint.Length < Maximum_Length then
		increase = 0.5
	end
end

--//Main Code
tool.Equipped:Connect(function()
	character = tool.Parent
	E_Key_Connection = E_Key_Remote.OnServerEvent:Connect(function(player)
		if player.Character == character then
			ropeconstraint.Length += increase
		end
	end)

	Q_Key_Connection = Q_Key_Remote.OnServerEvent:Connect(function(player)
		if player.Character == character then
			character.Torso.Anchored = true
			ropeconstraint.Length -= decrease
			wait()
			character.Torso.Anchored = false
		end
	end)

	LMB_Connection = LMB_Remote.OnServerEvent:Connect(function(player, target)
		if player.Character == character then
			local Distance = (character.PrimaryPart.Position - target.Position).Magnitude

			local Rope_Attached = target.Rope_Attached.Value

			if Rope_Attached == false and (character.PrimaryPart.Position - target.Position).Magnitude < Connection_Distance then
				target.Rope_Attached.Value = true
				local blocks = target.Parent

				if blocks.Name == character.Name then

					print("Distance is "..Distance.." Connection Distance is "..Connection_Distance)
					attachment0.Parent = target
					attachment1.Parent = character.PrimaryPart
					ropeconstraint.Attachment0 = attachment0
					ropeconstraint.Attachment1 = attachment1
					ropeconstraint.Color = BrickColor.new("Black")
					ropeconstraint.Visible = true
					ropeconstraint.Parent = character.PrimaryPart
					ropeconstraint.Length = Distance

					Handle_Rope_Increment(character)
				end
			end
		end
	end)

	Rope_Connection = ropeconstraint.Changed:Connect(function()
		Handle_Rope_Increment(character)
	end)
end)

--//Tool Unequipped
tool.Unequipped:Connect(function()
	E_Key_Connection:Disconnect()
	Q_Key_Connection:Disconnect()
	LMB_Connection:Disconnect()
	Rope_Connection:Disconnect()
end)

i have 2 codes mine is disabled and yours is enabled

i Fixed it by making Rope Check Function and then Disconnecting The function once tool is unequiped

wait(game.Loaded)

--// Statements
local LMB_Remote = script.Parent.LMB_Remote
local E_Key_Remote = script.Parent.E_Key_Remote
local Q_Key_Remote = script.Parent.Q_Key_Remote

local E_Key_Connection: RBXScriptConnection = nil
local Q_Key_Connection: RBXScriptConnection = nil
local LMB_Connection: RBXScriptConnection = nil
local Rope_Check_Connection: RBXScriptConnection = nil

local tool = script.Parent

--//Main Code
tool.Equipped:Connect(function()
	LMB_Connection = LMB_Remote.OnServerEvent:Connect(function(player, target)

		local Distance = (player.Character.HumanoidRootPart.Position - target.Position).Magnitude
		local Connection_Distance = 50
		local Maximum_Length = 50
		local minimumLength = 5.5
		local decrease = 0.5
		local increase = 0.5

		local Rope_Attached = target.Rope_Attached.Value
		
		local blocks = target.Parent
		
		if Rope_Attached == false and (player.Character.HumanoidRootPart.Position - target.Position).Magnitude < Connection_Distance and blocks.Name == player.Name then
			local ropeconstraint = Instance.new("RopeConstraint")
			local attachment0 = Instance.new("Attachment")
			local attachment1 = Instance.new("Attachment")
			
			attachment0.Parent = target
			
			attachment1.Parent = script.Parent.Parent.Torso
			ropeconstraint.Parent = script.Parent.Parent.Torso
			
				ropeconstraint.Attachment0 = attachment0
			ropeconstraint.Attachment1 = attachment1
			
			ropeconstraint.Color = BrickColor.new("Black")
			
			ropeconstraint.Visible = true
			target.Rope_Attached.Value = true
			
				ropeconstraint.Length = Distance
			
--//Functions
			local function Rope_Check()
				if ropeconstraint.Length < minimumLength then
					ropeconstraint.Length = minimumLength
					decrease = 0
				end
				if ropeconstraint.Length < 7 then
					player.Character.Humanoid.JumpPower = 0
					decrease = 0.5
				end
				if ropeconstraint.Length > minimumLength then
					decrease = 0.5
				end

				if ropeconstraint.Length > 6.9 then
					player.Character.Humanoid.JumpPower = 50
					decrease = 0.5
				end
				if ropeconstraint.Length > Maximum_Length then
					increase = 0
				end
				if ropeconstraint.Length < Maximum_Length then
					increase = 0.5
				end
			end
			
			
		Rope_Check()
		
			E_Key_Connection = E_Key_Remote.OnServerEvent:Connect(function()
				ropeconstraint.Length += increase
			end)

			Q_Key_Connection = Q_Key_Remote.OnServerEvent:Connect(function()


				player.Character.Torso.Anchored = true
				ropeconstraint.Length -= decrease
				wait()
				player.Character.Torso.Anchored = false
			end)
			
		Rope_Check_Connection =	ropeconstraint.Changed:Connect(Rope_Check)
			
		--//Tool Unequipped
		tool.Unequipped:Connect(function()
			E_Key_Connection:Disconnect()
			Q_Key_Connection:Disconnect()
				LMB_Connection:Disconnect()
				Rope_Check_Connection:Disconnect()
			end)
			end
	end)
	end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.