Problem With Boolean Inside Of Touched Function

I’ve got a function that lets a player climb, it is a custom climbing script I made a few days ago. It is activated by the event Torso.Touched.

My problem is whenever it is touched, it sets a bool to true, and when the output should print true AND ONLY true, it instead prints something like this

true, false, true, false, true, false, true, false – It kinda just bounces between the 2???

Here is an EXTREMELY simplified version of it.

local Player = game.Players.LocalPlayer
local Character = script.Parent
local Torso = Character:WaitForChild("Torso")
local DebugWall = false

Torso.Touched:Connect(function ()
	DebugWall = true
end)


while task.wait(0.1) do
	print(DebugWall)
end

if you insert this into StarterCharacterScripts you should get my problem

2 Likes

Bumping this, urgently looking for answer

1 Like

I think this should fix the problem.

local Player = game.Players.LocalPlayer
local Character = script.Parent
local Torso = Character:WaitForChild("Torso")
local DebugWall = false
local Debounce = false

Torso.Touched:Connect(function ()
    if not Debounce then
        DebugWall = true
        Debounce = true
    end
end)

while task.wait(0.1) do
    print(DebugWall)
end

task.wait(1)
Debounce = false
1 Like

it still bounces in-between printing true and false

1 Like

I tried a bunch of methods.

The fact is that Roblox touch events can be unreliable when you are looking for “contact” instead of being “inside” a part.

Here is an example of how to do it by adding an additional part.

It seems to work without issue.

Climb.rbxl (54.8 KB)

You do not need the Attribute “Climb” that I added to the part. I just added it so you can turn walls on and off if you want.

1 Like

what, thats awesome! That works perfectly, thanks for the help!

1 Like