So i want to make when player touches the part it stops the fade part function. if player resets. however, it for some reason wont stop.
local ts=game:GetService("TweenService")
local part=script:FindFirstAncestorWhichIsA("BasePart")
local status=part.Status
local transparency=part.Transparency
local localplr=game.Players.LocalPlayer
local event=Instance.new("BindableEvent",part)
event.Name="reset"
local deb=false
return function()
local touchedParting=nil
local function touchedPart()
local hit=touchedParting
local plr=game.Players:GetPlayerFromCharacter(hit.Parent)
if plr==localplr then
if status.Value=="Normal" and deb==false then
status.Value="Fading"
local fadeTween=ts:Create(part,TweenInfo.new(1),{Transparency=1})
fadeTween:Play()
task.wait(1)
part.CanCollide=false
status.Value="Faded"
task.wait(3)
status.Value="Regenerating"
local unfadeTween=ts:Create(part,TweenInfo.new(1),{Transparency=transparency})
unfadeTween:Play()
task.wait(1)
part.CanCollide=true
status.Value="Normal"
end
end
end
local currentSpawn=nil
part.Touched:Connect(function(hit)
touchedParting=hit
currentSpawn=coroutine.create(touchedPart)
coroutine.resume(currentSpawn)
end)
event.Event:Connect(function()
if currentSpawn then
coroutine.close(currentSpawn)
currentSpawn=nil
print("cancelled")
end
part.Transparency=transparency
part.CanCollide=true
deb=true
status.Value="Normal"
task.delay(1,function()
deb=false
end)
end)
game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("PlayerReseted").OnClientEvent:Connect(function()
event:Fire()
end)
end
