Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I am trying to make wall crawling script but I cant even start crawling on the wall, why?

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

0

The distance is from UpperTorso center pos and the wall center pos... this may be the error

0

I tried removing the distance, still not able to stick. I also tried removing onWall and it also didnt helped.

0

Done

0

Error was basically on line 12

0

nice u gave out ur whole code

0

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

1 answer

Hello, HeyItzDanniee!

--// 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") or char:FindFirstChild("Torso") --Made your script R6, as my character is R6
local part = game.Workspace.Part

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) -- Use :Connect as :connect is deprecated
	local distance = (part.Position - torso.Position).magnitude -- Test the position based on the place player pressed E, not based on spawn position
	if distance < (0.5) then --0.5 is a REALLY small number, as it tests from the parts CENTER, try printing "distance"....
		if key.KeyCode == Enum.KeyCode.E then
			if onWall == false then  --Moved this as if player press any keys, he will not sticky, only E
				onWall = true --I am setting this so I will be able to get the player off the wall or do different actions
				attach.Attachment0 = attach1
				attach.Attachment1 = attach2
				attach.Visible = true
			end
        end
    end
end)

Good Luck with your games

This discussion is preserved as it was. New answers, comments, and votes are closed.