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