If statement not working

Hello! Why are these two if statements not working?
if Rope.Length ~= 2 then
if Rope.Length ~= 30 then

script:

local hrpAttachment
local RopeAttachment
local Rope
local RopeSpawned = false
local RopeLength = 5
local RsLongerYes
local RsShorterYes
 
local function DestroyRope()
        if RopeSpawned == true then
               
                Rope.Parent = nil
                RopeAttachment.Parent = nil
                hrpAttachment = nil
                RopeAttachment = nil
               
                CAS:UnbindAction("DestroyRope")
               
                RopeSpawned = false
               
                humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
               
                humanoid.WalkSpeed = 21
        end
end
 
local function FindGrapplePart()
        for i, v in pairs(workspace.GrappleParts:GetChildren()) do
                if v:IsA("BasePart") then
                        if (hrp.Position - v.Position).magnitude < GrappleDistance then
                                far = (hrp.Position - v.Position)
                                GrapplePart = v
                        end
                end
        end    
end
 
rs:BindToRenderStep("ClosestGrapPart", 1, FindGrapplePart)
 
local function IsOnGround()
        if humanoid.FloorMaterial ~= Enum.Material.Air then
                DestroyRope()
                rs:UnbindFromRenderStep("IsOnGround")
                humanoid:ChangeState(Enum.HumanoidStateType.Landed)
                rs:UnbindFromRenderStep("RopeLong")
                rs:UnbindFromRenderStep("RopeShort")
        end
end
 
local function Grapple()
        if humanoid.FloorMaterial == Enum.Material.Air and RopeSpawned == false and GrapplePart ~= nil and (hrp.Position - GrapplePart.Position).magnitude < GrappleDistance then
                hrpAttachment = Instance.new("Attachment")
                hrpAttachment.Parent = hrp
               
                RopeAttachment = Instance.new("Attachment")
                RopeAttachment.Parent = GrapplePart
               
                Rope = Instance.new("RopeConstraint")
                Rope.Parent = workspace
                Rope.Visible = true
                Rope.Length = (hrp.Position - GrapplePart.Position).magnitude
                Rope.Attachment0 = hrpAttachment
                Rope.Attachment1 = RopeAttachment
               
                RopeSpawned = true
                SpinJumpDB = false
               
                CAS:BindAction("DestroyRope", DestroyRope, false, Enum.KeyCode.Space)
                CAS:UnbindAction("groundpound")
               
                humanoid.WalkSpeed = 40
               
                rs:BindToRenderStep("IsOnGround", 1, IsOnGround)
        end
end
 
local function RopeShorter()
        if Rope.Length ~= 30 then
                Rope.Length = Rope.Length - .099               
        end    
end
 
local function RopeLonger()
        if Rope.Length ~= 2 then
                Rope.Length = Rope.Length + .099
        end            
end
 
UIS.InputBegan:Connect(function(input)
        if RopeSpawned == true and input.KeyCode == Enum.KeyCode.F then
                rs:BindToRenderStep("RopeLong", 1, RopeLonger)
        end
end)
 
UIS.InputEnded:Connect(function(input)
        if RopeSpawned == true and input.KeyCode == Enum.KeyCode.F then
                rs:UnbindFromRenderStep("RopeLong")    
        end    
end)
 
UIS.InputBegan:Connect(function(input)
        if RopeSpawned == true and input.KeyCode == Enum.KeyCode.G then
                rs:BindToRenderStep("RopeShort", 1, RopeShorter)
        end
end)
 
UIS.InputEnded:Connect(function(input)
        if RopeSpawned == true and input.KeyCode == Enum.KeyCode.G then
                rs:UnbindFromRenderStep("RopeShort")   
        end    
end)
 
CAS:BindAction("Grapple", Grapple, false, Enum.KeyCode.E)


also is there any other better way of making a grappling hook?
1 Like

The if statement is correct, i would say the error is in

But i am not sure, should work correctly, not sure why it didn’t

Edit: I’ve never used ropes so i may and possibly am wrong

where is the error? Many people have told me its bcuz of that, but idk what the error in it is

if Rope.Length == 2 then
if Rope.Length == 30 then

or

if Rope.Length >= 2 then
if Rope.Length >= 30 then

no i wanna restrict how long the rope can go

1 Like

Maybe try to switch Rope.Length ~= 2 with Rope.Length >= 2 and Rope.Length ~= 30 with Rope.Length <= 30.
Also if statements in RopeShorter() and RopeLonger() should switch inbetween.

There are the errors in your script
image

The code he posted probably isn’t the entire code.

ok m8




-- Solid Variables

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
local UIS = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local CAS = game:GetService("ContextActionService")
local CS = game:GetService("CollectionService")
local humanoid = script.Parent:WaitForChild("Humanoid")
local RightArm = script.Parent["Right Arm"]
local RightLeg = script.Parent["Right Leg"]
local LeftLeg = script.Parent["Left Leg"]
local LeftArm = script.Parent["Left Arm"]
local WallJumpAble = CS:GetTagged("WallJumpAble")
local Debris = game:GetService("Debris")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local hrp = humanoid.RootPart
local head = script.Parent.Head
local camera = workspace.CurrentCamera
local Torso = script.Parent.Torso

-- Anims

local groundPoundAnim = humanoid:LoadAnimation(workspace.GroundPound)
local groundPoundSpin = humanoid:LoadAnimation(workspace.GroundPoundSpin)
local groundPoundStop = humanoid:LoadAnimation(workspace.GroundPoundStop)
local DiveAnim = humanoid:LoadAnimation(workspace.Dive)
local SlideKickAnim = humanoid:LoadAnimation(workspace.SlideKick)
local CrouchIdle = humanoid:LoadAnimation(workspace.CrouchIdle)
local CrouchWalk = humanoid:LoadAnimation(workspace.CrouchWalk)
local Holding_WalkAnim = humanoid:LoadAnimation(workspace.Walk_Carry)
local Holding_IdleAnim = humanoid:LoadAnimation(workspace.Idle_Carry)
local Holding_ThrowAnim = humanoid:LoadAnimation(workspace.HoldThrow)
local SpinJumpAnim = humanoid:LoadAnimation(workspace.SpinJump)
local SpinJump_Carry = humanoid:LoadAnimation(workspace.SpinJump_Carry)
local Slide_Carry = humanoid:LoadAnimation(workspace.SlideKick_Carry)
local RBX_Jump = humanoid:LoadAnimation(workspace.Jump_Anim)
local RBX_Fall = humanoid:LoadAnimation(workspace.Fall_Anim)
local WallJump = humanoid:LoadAnimation(workspace.WallJump)

-- true / false Variables

local isGroundPounding = false
local isOnWall = false
local Left = false
local Right = false
local Dismount = false
local welded = false
local isDashing = false
local DB = false
local DashDB = false
local isSlideKicking = false
local IsCrouching = false
local isBoxWeldSpawned = false
local SpinJumpDB = false
local IsGrappling = false
local GroundPoundDB = false

-- Number Variables

local GrappleDistance = 15
local far = 8

yea, btw i wanna restrict it so that the length of the rope cant go over 30 and cant go under 2

Then if statements in RopeShorter() and RopeLonger() should switch in-between.

1 Like

rope doesnt extend now, yes yes yes

i said yes yes yes so mesage is over 20 cahracters

Did you switch the entire codeblock or just the statement part?

if statements

local function RopeShorter()
	if Rope.Length >= 30 then
		Rope.Length = Rope.Length - .099		
	end	
end

local function RopeLonger()
	if Rope.Length <= 2 then
		Rope.Length = Rope.Length + .099
	end		
end

wait a minute i forgot to change the numbers

yep that worked im dumm, thanks a lot

btw the problem has been solved, but if you were to make a grappling hook, would u use a rope constraint or is that a bad way of doing it?

Answer is I don’t know, I never tried to do something like that before.

mk i jsut wanted to make sure, thanks for the help and have a great day!