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

How to make a when not Touched event in brick?

Asked by 6 years ago

Ok, so when you touch this brick, something appears; nothing more I can really say:

local Part = script.Parent
local talkbox = game.Workspace.TalkBoxes.CastleDoors.Noobs.TalkBoxOne

Part.Touched:connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid")
    if H then
        talkbox.TalkBox.Transparency = 0.5
        talkbox["Exclamation Mark"].PartA.Transparency = 0
        talkbox["Exclamation Mark"].PartB.Transparency = 0
    end
end)

This script works fine, how do I make it so when not touched, all 3 bits' Transparency will go back to 1?

1 answer

Log in to vote
0
Answered by 6 years ago

Hey SomeRandomGuy13564, ### So, I think that what you are asking for is quite simple. All you need to use is a debounce and a boolean to switch between two of the different states. Remember that this will mean you will need to give the script a cooldown of how much time it needs in between touches in-order to detect the next touch. So, if it needs 0.5 seconds between each touch, then it will do so with debounce. Well, let me demonstrate rather than just tell you how to do it.

Script

local part = script.Parent; -- The part.
local cool_down = 1; -- The amount of time it will wait before being able to fire the touched function again.
local has_touched, can_touch = false, true; -- Two booleans, one for cooldown and the other for switching between states of function.

part.Touched:Connect(function(hit) 
    local hum = hit.Parent:FindFirstChild("Humanoid");
    if hum and can_touch == true then -- Checks if can_touch is true, so if it's false then it won't execute, allowing for cooldown to be done.
        can_touch = false; -- Sets can_touch to false so that it can't be executed until can_touch is set to true.
        if has_touched then -- Checks for one state of the function, which is if the part has been touched already.
            has_touched = false; -- Sets has_touched to false to allow the other state of the function to run when this function is executed again.
            -- Whatever you need to do if it has been touched.
        else
            has_touched = true; -- Sets has_touched to true to allow the other state of the function to run when this function is executed again.
            -- Whatever you need to do if it is touched.
        end -- end for the second if statement.
        wait(cool_down); -- Waits for the cool_down amount of time.
        can_touch = true; -- Sets can_touch to true so that the function can be executed again.
    end -- end for first if statement
end) -- end for anonymous function

Well, I hope I helped, and have a wonderful day/night.

~~ KingLoneCat

0
Doesn't work :/ CaptaiinNoob 52 — 6y
0
Invite me to your TeamCreate. I've already tested this script in Studio, I know it works. KingLoneCat 2642 — 6y
Ad

Answer this question