Script door glitches

  1. What do you want to achieve?
    When you touch an part it uses tween service and smoothly put it at transparency 1

  2. What is the issue?

    , whenever you touch the door and keep at touching it, it will glitch and it won’t work again.

  3. What solutions have you tried so far? Rewrite script 5 times,
    looked at devhub.

local TweenService = game:GetService("TweenService")

local part = script.Parent
local cd = false
local goal =  {
	Transparency = 1,
	Color = Color3.new(0.901961, 0.737255, 1)	
	
}

local info = TweenInfo.new(
	1,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	true,
	1
)
local isTouched = false
local parttween = TweenService:Create(part, info, goal)

part.Touched:Connect(function(otherpart)
	if not isTouched then
		isTouched = true
		local humanoid = otherpart.Parent:FindFirstChildWhichIsA("Pants")


		if humanoid then	
			parttween:Play()
			wait(0.7)
			part.CanCollide = false
			cd = true
			isTouched = true
			if script.Parent.GRANTED.IsPlaying then
				script.Parent.GRANTED:Stop()
			else
				script.Parent.GRANTED:Play()
			wait(3)
			cd = false
				part.CanCollide = true
				isTouched = false
				isTouched = false
			end
		end

	end
end)
2 Likes

why isTouched = false twice times in the last wait?

1 Like

Cause I thought that if I put it twice it should work, still with only 1 also glitches.

try to change this:

	if not isTouched then

to this:

if isTouched == false then
1 Like

A reason why this isn’t working is if a part that doesn’t have pants touches the part, isTouched will never be set back to false.

I recommend adding isTouched = false to the end of the Touched Event and instead of trying to find pants, look for a humanoid.
Also you only need to change the variable once.

If I look at humanoid, it gives error otherwise if i use pants there’s no problem

You need to move isTouched = false to the end of the “if not isTouched then” statement, like this.

local TweenService = game:GetService("TweenService")

local part = script.Parent
local cd = false
local goal =  {
	Transparency = 1,
	Color = Color3.new(0.901961, 0.737255, 1)	

}

local info = TweenInfo.new(
	1,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	true,
	1
)
local isTouched = false
local parttween = TweenService:Create(part, info, goal)

part.Touched:Connect(function(otherpart)
	if not isTouched then
		isTouched = true
		
		local humanoid = otherpart.Parent:FindFirstChildWhichIsA("Humanoid")


		if humanoid then	
			parttween:Play()
			wait(0.7)
			part.CanCollide = false
			cd = true
			if script.Parent.GRANTED.IsPlaying then
				script.Parent.GRANTED:Stop()
			else
				script.Parent.GRANTED:Play()
				wait(3)
				cd = false
				part.CanCollide = true
			end
		end
		
		isTouched = false

	end
end)
2 Likes

I’ll try ()()()()()()()()()()()(

Thanks man, that helped alot!!