Alright, So in this script I am trying to turn the door invisible when the player is tocuhing a brick, and when they stop touching it, it turns the door back to normal. But the glitch i’ve been finding is that the door never turns back and I dont know what to do. So far i’ve tried switching around the if statements, adding else statements and other things that would change the logic a bit, but nothing is working.
Thanks for your help in advance
Script:
local door = workspace.Door
local StandOn = door.Standon
StandOn.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
door.Transparency = 0.8
door.CanCollide = false
end
if hum and hit.TouchEnded then
door.Transparency = 0
door.CanCollide = true
end
end)
I suggest using the TouchEnded event outside of the Touched event.
Also, if you want to prevent from the same player to touch again and again( you could add a debounce for him by assigning the user id as a key, and true/false as its value, etc.
`local Workspace = workspace
local Door = Workspace.Door
local Standon = Door.Standon
local Connection
local function OnTouched(Part)
if Connection then return end
local function OnTouchEnded(_Part)
if Part ~= _Part then return end
Connection:Disconnect()
Door.Transparency = 0
Door.CanCollide = true
end
local Model = Part:FindFirstAncestorOfClass("Model")
if not Model then return end
local Humanoid = Model:FindFirstChildOfClass("Humanoid")
if (not Humanoid) or Humanoid.Health <= 0 then return end
Connection = Standon.TouchEnded:Connect(OnTouchEnded)
Door.Transparency = 0.8
Door.CanCollide = false
end
Standon.Touched:Connect(OnTouched)`