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)
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)