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

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

Asked by 7 years ago

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)
0
You cannot print boolean values. Use a tostring(). hiimgoodpack 2009 — 7y
1
Yes you can. Azarth 3141 — 7y
0
yea u can lol outlook1234567890 115 — 7y
0
well one time it gave me a error maybe it was for something else hiimgoodpack 2009 — 7y

1 answer

Log in to vote
0
Answered by
iddash 45
7 years ago
Edited 7 years ago

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.

Ad

Answer this question