What do you want to achieve?
When you touch an part it uses tween service and smoothly put it at transparency 1
What is the issue?
, whenever you touch the door and keep at touching it, it will glitch and it won’t work again.
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)
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.
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)