Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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.

0
The distance is from UpperTorso center pos and the wall center pos... this may be the error Leamir 3138 — 5y
0
I tried removing the distance, still not able to stick. I also tried removing onWall and it also didnt helped. HeyItzDanniee 252 — 5y
0
Done Leamir 3138 — 5y
0
Error was basically on line 12 Leamir 3138 — 5y
View all comments (2 more)
0
nice u gave out ur whole code TheluaBanana 946 — 5y
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 HeyItzDanniee 252 — 5y

1 answer

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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

Ad

Answer this question