Function isnt running?

function casthookRight(name, t, state)
	print("Running")
	if name == "Right" and state == Enum.UserInputState.Begin then
		
		print("Running checkpoint 2")
		if not rightHooked then
			print("Casting Hook")
			local anchor = Instance.new("Part", grapples)
			anchor.Name = "Right"
			anchor.Anchored = true
			anchor.Size = Vector3.new(1, 1, 1)
			anchor.Position = mouse.Hit.p
			if (anchor.Position - humroo.Position).Magnitude > range then anchor:Destroy() return end
			setVelocity(anchor, force)
			rightHooked = true
			if rightHooked and leftHooked then
				setVelocityTwo(anchor, grapples.Left)
			end
		end
		if rightHooked == false then
			setGyroNil()
			setVelocityNil()
		end
	end

	if name == "Right" and state == Enum.UserInputState.End then
		rightHooked = false

		grapples.Right:Destroy()
		if getChild("Left", grapples) ~= nil then
			setVelocity(grapples.Left)
		else
			setVelocityNil()
			setGyroNil()
		end
	end
end

The function itself

bindService:BindAction("Right", casthookRight, false, Enum.KeyCode.E)

The binding line of code

Is this ever being reached? Can you show the full script?

alr, and yes it reaches, considering that the first debug line runs line 2

--odm client
local player = game.Players.LocalPlayer--we get the player
local character = player.Character or player.CharacterAdded:Wait()--we get the character
local mouse = player:GetMouse()--we get the mouse
local range = 400--set max anchoring range
local force = 3000--the force at which the player will move toward target
local boost = 4000--boosted force
local rightHooked = false--whetherether the right gear is anchored
local leftHooked = false--whether the left gear is anchored
local boosted = false--whether the odm is boosted
local bothHooked = false--whether both gears are hooked
local rightGear = character:WaitForChild("RightGear")--the right gear
local leftGear = character:WaitForChild("LeftGear")--the left gear
local humroo = character:WaitForChild("HumanoidRootPart")--the humanoid root part
local grapples = Instance.new("Folder", character)--a new folder where grapples will be kept
grapples.Name = "Grapples"
local bindService = game:GetService("ContextActionService")
local runService = game:GetService("RunService")
local function updateGyro()
	local gyro = humroo:WaitForChild("AlignOrientation")
	if grapples:FindFirstChild("MiddlePart") then
		gyro.CFrame = grapples.MiddlePart.CFrame
		return "Updated"
	end
	if grapples:FindFirstChild("Right") then
		gyro.CFrame = grapples.Right.CFrame
		return "Updated"
	end
	if grapples:FindFirstChild("Left") then
		gyro.CFrame = grapples.Left.CFrame
		return "Updated"
	end
	return nil
end
local function getChild(childName, Parent)
	return Parent:FindFirstChild(childName)
end
local function setGyro(part)
	local gyro = getChild("AlignOrientation", humroo)
	gyro.CFrame = part.CFrame
	return "completed"
end
local function setVelocity(anchor, f)
	local velocity = getChild("LineForce", humroo)
	if velocity == nil then return end
	script.SetVelocity:FireServer(f, humroo, anchor)
	return "completed"
end
local function setVelocityTwo(anchor1, anchor2)
	local velocity = getChild("LineForce", humroo)
	if bothHooked == false then return end
	local setPart = Instance.new("Part", grapples)
	setPart.Name = "MiddlePart"
	setPart.Anchored = true
	local newPosition = (anchor1.Position + anchor2.Position)/2
	setPart.Position = newPosition
	setVelocity(setPart)
end
local function setVelocityNil()
	local velocity = getChild("LineForce", humroo)
	script.SetVelocity:FireServer(0, nil, nil)
	boosted = false
end
local function setGyroNil()
	local gyro = getChild("AlignOrientation", humroo)
	gyro.CFrame = CFrame.new(0, 0, 0)
end
function casthookRight(name, t, state)
	print("Running")
	if name == "Right" and state == Enum.UserInputState.Begin then
		print("2")
		print("Running checkpoint 2")
		if not rightHooked then
			print("Casting Hook")
			local anchor = Instance.new("Part", grapples)
			anchor.Name = "Right"
			anchor.Anchored = true
			anchor.Size = Vector3.new(1, 1, 1)
			anchor.Position = mouse.Hit.p
			if (anchor.Position - humroo.Position).Magnitude > range then anchor:Destroy() return end
			setVelocity(anchor, force)
			rightHooked = true
			if rightHooked and leftHooked then
				setVelocityTwo(anchor, grapples.Left)
			end
		end
		if rightHooked == false then
			setGyroNil()
			setVelocityNil()
		end
	end

	if name == "Right" and state == Enum.UserInputState.End then
		rightHooked = false

		grapples.Right:Destroy()
		if getChild("Left", grapples) ~= nil then
			setVelocity(grapples.Left)
		else
			setVelocityNil()
			setGyroNil()
		end
	end

end
function casthookLeft(name, t, state)
	print("Running")
	if name == "Left" and state == Enum.UserInputState.Begin then
		print("Running2")
		if not leftHooked then
			local anchor = Instance.new("Part", grapples)
			print("Casting Hook")
			anchor.Name = "Left"
			anchor.Anchored = true
			anchor.Size = Vector3.new(1, 1, 1)
			anchor.Position = mouse.Hit.p
			if (anchor.Position - humroo.Position).Magnitude > range then anchor:Destroy() return end
			setVelocity(anchor, force)
			leftHooked = true
			if rightHooked and leftHooked then
				setVelocityTwo(anchor, grapples.Right)
			end
		end
		if leftHooked then
			setGyroNil()
			setVelocityNil()
		end
	end
	if name == "Left" and state == Enum.UserInputState.End then
		leftHooked = false
		grapples.Left:Destroy()
		if getChild("Right", grapples) ~= nil then
			setVelocity(grapples.Right)
		else
			setVelocityNil()
			setGyroNil()
		end
	end
end
local function boost(name, t, state)
	if name == "Boost" and boosted == false and state == Enum.UserInputState.Begin then
		if grapples:FindFirstChild("MiddlePart") then
			setVelocity(grapples["MiddlePart"], boost)
			boosted = true
			return "boosted"
		end
		if grapples:FindFirstChild("Right") then
			setVelocity(grapples["Right"], boost)
			boosted = true
			return "boosted"
		end
		if grapples:FindFirstChild("Left") then
			setVelocity(grapples["Left"], boost)
			boosted = true
			return "boosted"
		end
	end
	if name == "Boost" and boosted == true and state == Enum.UserInputState.End then
		if grapples:FindFirstChild("MiddlePart") then
			setVelocity(grapples["MiddlePart"], force)
			boosted = false
			return "boosted"
		end
		if grapples:FindFirstChild("Right") then
			setVelocity(grapples["Right"], force)
			boosted = false
			return "boosted"
		end
		if grapples:FindFirstChild("Left") then
			setVelocity(grapples["Left"], force)
			boosted = false
			return "boosted"
		end
	end
end
bindService:BindAction("Left", casthookLeft, false, Enum.KeyCode.Q)
bindService:BindAction("Right", casthookRight, false, Enum.KeyCode.E)
bindService:BindAction("Space", boost, false, Enum.KeyCode.Space)
runService:BindToRenderStep("UpdateGyro", 1, updateGyro)
--gamepad & mobile controls to be added in the future

Problem fixed, used UserInputService

1 Like