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)
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)