I made this simple, short script. But I cant really "stick" to the wall. I want them to stick the player by pressing E but I need to find the distance.. I want the max distance he can stick away from to be 0.5. However, I am able to stick the player to the wall by removing the "onWall" and "distance", but I really need them.
--// Wall Crawl Prototype Script by HeyItzDanniee \\ --
--// Variables
local players = game:GetService("Players")
local plr = players.LocalPlayer
local char = plr.Character
local torso = char:FindFirstChild("UpperTorso")
local part = game.Workspace.Part
local distance = (part.Position - torso.Position).magnitude
attach1 = Instance.new("Attachment", torso)
attach2 = Instance.new("Attachment", part)
attach = Instance.new("CylindricalConstraint", torso)
local uis = game:GetService("UserInputService")
onWall = false
--// Functions:
uis.InputBegan:connect(function(key)
if onWall == false then onWall = true --I am setting this so I will be able to get the player off the wall or do different actions
if distance < (0.5) then --This is the distance I want this to work from, I am using magnitude to calculate the distance between the player`s torso and the wall
if key.KeyCode == Enum.KeyCode.E then
attach.Attachment0 = attach1
attach.Attachment1 = attach2
attach.Visible = true
end
end
end
end)
How it works: I am using a CylindricalConstraint to "stick" the player to the wall. I will add BodyVelocity and made the player move upwards if the onWall is true.

6 comments
The distance is from UpperTorso center pos and the wall center pos... this may be the error
I tried removing the distance, still not able to stick. I also tried removing onWall and it also didnt helped.
Done
Error was basically on line 12
nice u gave out ur whole code
Its not even working. Also I am going to add animations and a lot more so it will be nothing like this. All what this code does is to make you stick to the wall. Thats it. You cant even move.. lmao