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

Help with Conditional Statements?[Not Fixed]

Asked by 10 years ago

So,I was making a script that only executes one time if it's Touched but everything was find until I added TouchedEnded event,why and how do I fix it?

I also got an error saying:

Workspace.Part.Script:12: unexpected symbol near 'then'

Script:

local Part = script.Parent
local Touched = false--Debounce
--------------------------
    Part.Touched:connect(function(TouchedPart)
        Touched = true
        FoundHumanoid= TouchedPart.Parent:FindFirstChild("Humanoid")--Checks if it's a humanoid
                if not FoundHumanoid then
                    print("You're not a Character "..TouchedPart.Name.." !")
                    Touched = false
                else
                    if not Touched or Part.TouchedEnded:connect(function()
                        then
                        print("I haven't been touched!")
                            Touched = false
                        Part.Transparency = 1
                    else

                        Part.Transparency = 0.5
                            print("I've been touched")

                end 
            end
        end)
    end)

1 answer

Log in to vote
1
Answered by
Lacryma 548 Moderation Voter
10 years ago

Well, you cannot use an event in a conditional statement. Instead you should use the :wait() method of events to check whether the event has occurred or not. This is how it should look like.

local Part = script.Parent
local Touched = false--Debounce

    Part.Touched:connect(function(TouchedPart)
        Touched = true
        FoundHumanoid= TouchedPart.Parent:FindFirstChild("Humanoid")--Checks if it's a humanoid
                if not FoundHumanoid then
                    print("You're not a Character "..TouchedPart.Name.." !")
                    Touched = false
                else
                    if not Touched or Part.TouchEnded:wait()  then
                        print("I haven't been touched!")
                            Touched = false
                        Part.Transparency = 1
                    else
                        Part.Transparency = 0.5
                         print("I've been touched")
                end 
            end
    end)
0
I got a new error saying: TouchedEnded is not a valid member of Part. kevinnight45 550 — 10y
0
My mistake, it is "TouchEnded" Lacryma 548 — 10y
Ad

Answer this question