How can I make it so that I don't climb on mid air when there's no wall? The climb tool also make me climb the wall even though when I'm not activating the tool. Is there a way to fix it?

Here's a GIF to see what I mean:

https://gyazo.com/7330ad6b86c7834d7dcb708e049d9760

Here's an image of the layout from the tool:

https://gyazo.com/caf61a3935f5e08184b579ac594e8b66

This is a regular script that goes into the HopperBin tool:

EQ = false
Mag = false
HitPart = nil
Pl = script.Parent.Parent.Parent
Char = Pl.Character
Tor = Char.Torso

script.Parent.Selected:connect(function(mouse)
EQ = true
if Tor:findFirstChild("WallClimbV") ~= nil then
Tor.WallClimbV:remove()
end
end)

script.Parent.Deselected:connect(function(mouse)
EQ = false
if Tor:findFirstChild("WallClimbV") ~= nil then
Tor.WallClimbV:remove()
end
end)

while workspace:findFirstChild(script.Parent.Parent.Parent.Name) == nil do
wait(.1)
end

Tor.Touched:connect(function(hit)
if EQ == true then
if hit.Position.y >= Char.Torso.Position.y and hit.Size.y >= Char.Torso.Size.y then
HitPart = hit
else
HitPart = nil
end
end
end)

while true do
if EQ == true then
if HitPart ~= nil then
if (HitPart.Position - Tor.Position).magnitude <= HitPart.Size.x+1.5 or (HitPart.Position - Tor.Position).magnitude <= HitPart.Size.z+1.5 then
if Tor:findFirstChild("WallClimbV") == nil then
local bv = Instance.new("BodyVelocity")
bv.Parent = Tor
bv.Name = "WallClimbV"
bv.velocity = Vector3.new(0,Char.Humanoid.WalkSpeed,0)
bv.maxForce = Vector3.new(999999999999,999999999999,999999999999)
end
else
if Tor:findFirstChild("WallClimbV") ~= nil then
Tor.WallClimbV:remove()
end
HitPart = nil
end
else
if Tor:findFirstChild("WallClimbV") ~= nil then
Tor.WallClimbV:remove()
end
HitPart = nil
end
end
wait(.05)
end 

Many thanks my friends for your help and support!

2 comments

1

You might want to look into ray casting to determine if a block is infront of you. Touched can be a little unreliable in this instance especially when you are no longer touching the wall but still trying to get over it. Here's a bit on raycasting http://wiki.roblox.com/index.php?title=Making_a_ray-casting_laser_gun

0

^ An example of using raycasting to detect walls can be found in my WallJump script. I posted about it here: https://forum.scriptinghelpers.org/topic/14/wall-jump-game-mechanic