Can someone help me to fix this?

Hello, i’m trying to figure it out how to solve this problem. Is there sometime wrong about my script?

Here’s the example
https://gyazo.com/296da6536805f9b6d8850adb6f370ab0

Here’s the script.

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild(“Humanoid”)

wait()

attachment1 = char.HumanoidRootPart.RootAttachment
attachment0 = workspace.MagRopeSystem.GrappleHookZone.Rope.Attachment0

local ropeInstance = Instance.new(“RopeConstraint”,char)
local userinput = game:GetService(“UserInputService”)

ropeInstance.Visible = true
ropeInstance.Length = 20

magrope = true

ropeInstance.Enabled = false
ropeInstance.Attachment0 = attachment0
ropeInstance.Attachment1 = attachment1

local anim = hum:LoadAnimation(script.MagropeAnim)

userinput.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
for _,magRope in pairs(workspace.MagRopeSystem:GetChildren()) do
local mag = (magRope.Trigger.Position - char.HumanoidRootPart.Position).magnitude
if mag <= magRope.Configs.Range.Value then
if magrope == false then
magrope = true
print(“Rope Destroyed”);
char.HumanoidRootPart.RootAttachment.Position = Vector3.new(0, 0 ,0)
ropeInstance.Enabled = false
anim:Stop()
else
magrope = false
print(“Rope Conneted”);
char.HumanoidRootPart.RootAttachment.Position = Vector3.new(-2.161, 1.973, 0.389)
ropeInstance.Enabled = true
anim:Play()

		    end
		elseif input.KeyCode == Enum.KeyCode.Space then
			print("Space Rope Destroyed");
	        ropeInstance.Enabled = false	    
		 end
	end
end

end)

3 Likes

You never really explained what the problem was but I’ll take a guess. I think your problem is that it is not being destroyed, right? That’s because you never really put :Destroy() in the script.

You have to put a Destroy() command to destroy that part that you are not destroying

2 Likes

Okay i will explain it.

When the player Press E on the first trigger, it will work and the rope will placed, but in the second trigger, it will snap back to first trigger.

Work on first one.
https://gyazo.com/c95e1aedf80626904aa8bd0fdd31f285

Not working in the second trigger
https://gyazo.com/db262d696b2607d890b925ab7c6d3040

Here’s the screenshot.
https://gyazo.com/c7587f6215db10760517dcf0d5f26edc

1 Like

Ok, so you are looping through the system and looking for the first valid rope and then using that rope.

What you need to do, or what I would do, is check all the ropes in the system and find the rope closest to the character and then check if that rope is valid; and if so use the rope

I modified your code and I think it will work but no promises

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
wait()

attachment1 = char.HumanoidRootPart.RootAttachment
attachment0 = workspace.MagRopeSystem.GrappleHookZone.Rope.Attachment0

local ropeInstance = Instance.new("RopeConstraint",char)
local userinput = game:GetService("UserInputService")

ropeInstance.Visible = true
ropeInstance.Length = 20

magrope = true

ropeInstance.Enabled = false
ropeInstance.Attachment0 = attachment0
ropeInstance.Attachment1 = attachment1

local anim = hum:LoadAnimation(script.MagropeAnim)

userinput.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		local t = {};
		for _,magRope in pairs(workspace.MagRopeSystem:GetChildren()) do
			local mag = (magRope.Trigger.Position - char.HumanoidRootPart.Position).magnitude
			table.insert(t, {mag, magRope})
		end
		table.sort(t, function(a,b)
			return a[1] < b[1]
		end)
		
		local mag = t[1][1];
		local magRope = t[1][2];
		if mag <= magRope.Configs.Range.Value then
			if magrope == false then
				magrope = true
				print("Rope Destroyed");
				char.HumanoidRootPart.RootAttachment.Position = Vector3.new(0, 0 ,0)
				ropeInstance.Enabled = false
				anim:Stop()
			else
				magrope = false
				print("Rope Conneted");
				char.HumanoidRootPart.RootAttachment.Position = Vector3.new(-2.161, 1.973, 0.389)
				ropeInstance.Enabled = true
				anim:Play()
			end
		end
	elseif input.KeyCode == Enum.KeyCode.Space then
		print("Space Rope Destroyed");
	 	ropeInstance.Enabled = false	    
	end
end)
1 Like

It didn’t work. There’s an error code line 36

1 Like

fixed but you could’ve fixed it yourself if you looked at what i even did…

2 Likes

Thanks for help. I’m not pretty good at scripting.

2 Likes