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

How to make the TouchEnded function to activate when a player is not near the part??

Asked by 3 years ago

The TouchEnded part of this script is not working. Basically I am trying to make a part that changes to neon and does a fade effect on touch and when the player comes off the part, it goes back to ForceField and stops.

Script:

local part = script.Parent

local debounce = true

part.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
    if humanoid~= nil and debounce == true then
        debounce = false
        part.Transparency = 0.05
        wait(0.05)
        part.Transparency = 0.10
        wait(0.05)
        part.Transparency = 0.15
        wait(0.05)
        part.Transparency = 0.20
        wait(0.05)
        part.Transparency = 0.25
        wait(0.05)
        part.Transparency = 0.30
        wait(0.05)
        part.Transparency = 0.35
        wait(0.05)
        part.Transparency = 0.40
        wait(0.05)
        part.Transparency = 0.45
        wait(0.05)
        part.Transparency = 0.50
        wait(0.05)
        part.Transparency = 0.55
        wait(0.05)
        part.Transparency = 0.60
        wait(0.05)
        part.Transparency = 0.65
        wait(0.05)
        part.Transparency = 0.70
        wait(0.05)
        part.Transparency = 0.75
        wait(0.05)
        part.Transparency = 0.80
        wait(0.05)
        part.Transparency = 0.85
        wait(0.05)
        part.Transparency = 0.90
        wait(0.05)
        part.Transparency = 0.95
        wait(0.05)
        part.Transparency = 1.00
        part.Material = Enum.Material.Neon
        wait(0.05)
        part.Transparency = 0.95
        wait(0.05)
        part.Transparency = 0.90
        wait(0.05)
        part.Transparency = 0.85
        wait(0.05)
        part.Transparency = 0.80
        wait(0.05)
        part.Transparency = 0.75
        wait(0.05)
        part.Transparency = 0.70
        wait(0.05)
        part.Transparency = 0.65
        wait(0.05)
        part.Transparency = 0.60
        wait(0.05)
        part.Transparency = 0.55
        wait(0.05)
        part.Transparency = 0.50
        wait(0.05)
        part.Transparency = 0.45
        wait(0.05)
        part.Transparency = 0.40
        wait(0.05)
        part.Transparency = 0.35
        wait(0.05)
        part.Transparency = 0.30
        wait(0.05)
        part.Transparency = 0.25
        wait(0.05)
        part.Transparency = 0.20
        wait(0.05)
        part.Transparency = 0.15
        wait(0.05)
        part.Transparency = 0.10
        wait(0.05)
        part.Transparency = 0.05
        wait(0.05)
        part.Transparency = 0.00
        wait(0.05)
        debounce = true
        end         
end)


part.TouchEnded:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
    if humanoid == nil then
        part.Material = Enum.Material.ForceField
        print("off")
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I added a constant Check() function after every wait to see if the part was touched or not.

local part = script.Parent
local debounce = true

part.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
    local player = hit.Parent
    if humanoid~= nil and debounce == true then
        debounce = false
        part.Transparency = 0.05
        repeat Color() until not hit ~= player
        if not hit ~= player then
            part.Material = "ForceField"
        end
        debounce = true
    end     
end)

function Color()
    wait(0.05)
    part.Transparency = 0.10

    wait(0.05)
    part.Transparency = 0.15

    wait(0.05)
    part.Transparency = 0.20

    wait(0.05)
    part.Transparency = 0.25

    wait(0.05)
    part.Transparency = 0.30

    wait(0.05)
    part.Transparency = 0.35

    wait(0.05)
    part.Transparency = 0.40

    wait(0.05)
    part.Transparency = 0.45

    wait(0.05)
    part.Transparency = 0.50

    wait(0.05)
    part.Transparency = 0.55

    wait(0.05)
    part.Transparency = 0.60

    wait(0.05)
    part.Transparency = 0.65

    wait(0.05)
    part.Transparency = 0.70

    wait(0.05)
    part.Transparency = 0.75

    wait(0.05)
    part.Transparency = 0.80

    wait(0.05)
    part.Transparency = 0.85

    wait(0.05)
    part.Transparency = 0.90

    wait(0.05)
    part.Transparency = 0.95

    wait(0.05)
    part.Transparency = 1.00
    part.Material = "Neon"

    wait(0.05)
    part.Transparency = 0.95

    wait(0.05)
    part.Transparency = 0.90

    wait(0.05)
    part.Transparency = 0.85

    wait(0.05)
    part.Transparency = 0.80

    wait(0.05)
    part.Transparency = 0.75

    wait(0.05)
    part.Transparency = 0.70

    wait(0.05)
    part.Transparency = 0.65

    wait(0.05)
    part.Transparency = 0.60

    wait(0.05)
    part.Transparency = 0.55

    wait(0.05)
    part.Transparency = 0.50

    wait(0.05)
    part.Transparency = 0.45

    wait(0.05)
    part.Transparency = 0.40

    wait(0.05)
    part.Transparency = 0.35

    wait(0.05)
    part.Transparency = 0.30

    wait(0.05)
    part.Transparency = 0.25

    wait(0.05)
    part.Transparency = 0.20

    wait(0.05)
    part.Transparency = 0.15

    wait(0.05)
    part.Transparency = 0.10
    wait(0.05)
    part.Transparency = 0.05
    wait(0.05)
    part.Transparency = 0.00
    wait(0.05)
end

Hope this helped - Mr Monkey :)

Found The Problem, The "Part" was still touching something. This checks if its touching the player.

0
Still doesn't work ;( Here's a video: https://gyazo.com/a8cca564e6f3e4d06ea0eb25722406e3 although the video cut a little early nathanielstanle 20 — 3y
0
is it supposed to be invisible when you step off of it? If so I made edits to my script Nervousmrmonkey2 118 — 3y
0
Not invisible but the material was supposed to be set to ForceField if a player is not touching the part. Thanks for all the help so far nathanielstanle 20 — 3y
0
Works great man! Just one thing that I want to know is if there is anyway to make it turn off smoother at the end. Like in this video, watch how it cuts off: https://gyazo.com/c24f36526dfc3a981af34960f2c35835 Any way to make a smoother transition?? Btw I deleted line 9 as I didn't want the part to be invisible. nathanielstanle 20 — 3y
View all comments (5 more)
0
I added back line 9, thought it was 0.95 when it was 0.05 XD nathanielstanle 20 — 3y
0
Ok. I will try to make it smoother your Welcome :) Nervousmrmonkey2 118 — 3y
0
Yh man thanks for all the help if you wanna see what I was doing with the script, I could link you the unfinished game nathanielstanle 20 — 3y
0
Nah its fine happy scripting :D Nervousmrmonkey2 118 — 3y
0
Mhm nathanielstanle 20 — 3y
Ad

Answer this question