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

Getting touched to be true when on the part and only false when you walk off?

I need help with a script that is supposed to change touching to true while you are on a part and change it to false when you walk off, but it doesn't work, it sets it to true but not false. Can someone help?

local touching = false
local canchange = false
local changeable = true
script.Parent.Touched:Connect(function(touched)
	touching = true
	canchange = false
	print(touching)
end)
script.Parent.TouchEnded:Connect(function(touched)
	if changeable == true then
		changeable = false
		canchange = true
		wait(1)
		if canchange == true then
			touching = false
		end
	changeable = true
	end
	print(touching)
end)

4 comments

0

You cannot print boolean values. Use a tostring().

1

Yes you can.

0

yea u can lol

0

well one time it gave me a error maybe it was for something else

1 answer

You've made it too complicated. Use this to help you.

local touched = false
script.Parent.Touched:Connect(function()
	if touched == false then
		print("true")
		touched = true
	end	

end)
script.Parent.TouchEnded:Connect(function()
	if touched == true then
		print("False")
		touched = false
	end

end)

This script works so if you want to use it then go ahead.

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