Context action service, move function not firing if player holds key, but firing only once

I made a wall climb system, and when the player is climbing he is supposed to move upwards whenever the Y key is hold, but his moving only one time per 1 hold

local cs = game:GetService("CollectionService")
local plr = game.Players.LocalPlayer
local char = script.Parent
local raycastparms = RaycastParams.new()
task.wait(2)
local attachofchar = Instance.new("Attachment",char.HumanoidRootPart)
local ap = Instance.new("AlignPosition",char)
ap.Mode = Enum.PositionAlignmentMode.OneAttachment
ap.Attachment0 = attachofchar
ap.MaxForce = math.huge
ap.Enabled = false
ap.MaxVelocity = 150
raycastparms.FilterDescendantsInstances = cs:GetTagged("Wall")
print(#cs:GetTagged("Wall"))
raycastparms.FilterType = Enum.RaycastFilterType.Whitelist
local isclimbing = false

local function checkwall()
    local raycastresult = workspace:Raycast(char.HumanoidRootPart.Position,char.HumanoidRootPart.CFrame.LookVector*15,raycastparms)
    if raycastresult ~= nil then
        isclimbing = true
        return isclimbing
    end
end

spawn(function()
    while wait(0.1) do
        if checkwall() == true then
            ap.Enabled = true
            ap.Position = char.HumanoidRootPart.Position
        else
            ap.Enabled = false
        end
    end
end)
local uis = game:GetService("UserInputService")

local function addorsub(actionname,userstate)
    if userstate == Enum.UserInputState.Begin then
        if isclimbing == true then
            if actionname == "up" then
                ap.Position += Vector3.new(0,1,0)
            elseif actionname == "down" then
                ap.Position -= Vector3.new(0,1,0)
            end
        end
    end
end
local cas = game:GetService("ContextActionService")
cas:BindAction("up",addorsub,false,Enum.KeyCode.Y)
1 Like

context action service only fires when you press the Butten and release

1 Like

how to do a player moving control, like when the W is pressed, the player keeps going

1 Like

wait i also see another problem, the action name will never be “down”

1 Like

this should work, try this

local cs = game:GetService("CollectionService")
local plr = game.Players.LocalPlayer
local char = script.Parent
local raycastparms = RaycastParams.new()
task.wait(2)
local attachofchar = Instance.new("Attachment",char.HumanoidRootPart)
local ap = Instance.new("AlignPosition",char)
ap.Mode = Enum.PositionAlignmentMode.OneAttachment
ap.Attachment0 = attachofchar
ap.MaxForce = math.huge
ap.Enabled = false
ap.MaxVelocity = 150
raycastparms.FilterDescendantsInstances = cs:GetTagged("Wall")
print(#cs:GetTagged("Wall"))
raycastparms.FilterType = Enum.RaycastFilterType.Whitelist
local isclimbing = false

local function checkwall()
	local raycastresult = workspace:Raycast(char.HumanoidRootPart.Position,char.HumanoidRootPart.CFrame.LookVector*15,raycastparms)
	if raycastresult ~= nil then
		isclimbing = true
		return isclimbing
	end
end

spawn(function()
	while wait() do
		if checkwall() == true then
			ap.Enabled = true
			ap.Position = char.HumanoidRootPart.Position
		else
			ap.Enabled = false
		end
	end
end)
local uis = game:GetService("UserInputService")

local function addorsub(actionname)
		if isclimbing == true then
			if actionname == "up" then
				ap.Position += Vector3.new(0,2,0)
			elseif actionname == "down" then
				ap.Position -= Vector3.new(0,2,0)
			end
		end
end
game:GetService("RunService").RenderStepped:Connect(function()
	local uis = game:GetService("UserInputService")
	if uis:IsKeyDown(Enum.KeyCode.E) then--change E to ur keycode to go up
		addorsub("up")
	elseif uis:IsKeyDown(Enum.KeyCode.Q) then--change Q to ur keycode to go down
		addorsub("down")
	end
end)

also sorry for late reply i guess

Do you know how a slide script works?

no, i haven’t tried creating one and idk if i would do it

2 Likes

Oh ok. Thx for answering btw lol

1 Like