Problem With Code Loop

I am Trying to make a Shield that Activate its core ect works fine
but The Core
Neon Ect keep Looping and i dont know how to fix t

Main Code

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local DeactivatedColor = Color3.fromRGB(75, 151, 75)
local ActivatedColor = Color3.fromRGB(166, 0, 0)

local Model = script.Parent
local ColorParts = Model.ColorParts
local HitPart = Model.Shield
local Button = Model.Button
local OwnerOnlyPrompt = Button.OwnerOnlyDoorPrompt

local isActive = false
local tEnabled = false
local Enabled = true

local function deactivate()
	isActive = false
	OwnerOnlyPrompt.ObjectText = "To Deactivate"

	for _, part in pairs(ColorParts:GetChildren()) do
		if part:IsA("BasePart") then
			part.Color = DeactivatedColor
			Button.BrickColor = BrickColor.new("Really red")
			if Enabled then
			script.Parent.Neon.Script4.Disabled = false
			wait(7)
			script.Parent.ActivationPart2.Transparency = 1
			script.Parent.Core.Script4.Disabled = false
			wait(7)
			script.Parent.Neon.Script4.Disabled = true
			wait(7)
			script.Parent.Core.Script4.Disabled = true
			script.Parent.Core.ParticleEmitter.Enabled = false
			script.Parent.LighteningParticleEmitters.Part.ParticleEmitter.Enabled = true
			script.Parent.LighteningParticleEmitters.Part.ParticleEmitter.Enabled = false
			script.Parent.ActivationPart.Transparency = 0
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.1
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.2
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.3
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.4
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.5
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.6
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.7
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.8
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.9
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 1
			wait(2)
			script.Parent.Core.Script.Disabled = false
			tEnabled = false -- Enable 't'
			script.Parent.Shield.Transparency = 0
			wait(0.6)
			script.Parent.Shield.Transparency = 0.1
			wait(0.6)
			script.Parent.Shield.Transparency = 0.2
			wait(0.6)
			script.Parent.Shield.Transparency = 0.3
			wait(0.6)
			script.Parent.Shield.Transparency = 0.4
			wait(0.6)
			script.Parent.Shield.Transparency = 0.5
			wait(0.6)
			script.Parent.Shield.Transparency = 0.6
			wait(0.6)
			script.Parent.Shield.Transparency = 0.7
			wait(0.6)
			script.Parent.Shield.Transparency = 0.8
			wait(0.6)
			script.Parent.Shield.Transparency = 0.9
			wait(0.6)
			script.Parent.Shield.Transparency = 1
			Enabled = false
			Button.BrickColor = BrickColor.new("Lime green")
			
            end
		end
	end
end

local function activate()
	isActive = true
	OwnerOnlyPrompt.ObjectText = "To Activate"

	for _, part in pairs(ColorParts:GetChildren()) do
		if part:IsA("BasePart") then
			part.Color = ActivatedColor
			Button.BrickColor = BrickColor.new("Really red")
			if not Enabled then
			script.Parent.Neon.Script3.Disabled = false
			wait(7)
			script.Parent.Core.Script3.Disabled = false
			wait(7)
			script.Parent.Neon.Script3.Disabled = true
			wait(7)
			script.Parent.Core.Script3.Disabled = true
			script.Parent.ActivationPart2.Transparency = 0
			script.Parent.Core.ParticleEmitter.Enabled = true
			script.Parent.LighteningParticleEmitters.Part.ParticleEmitter.Enabled = true
			script.Parent.ActivationPart.Transparency = 1
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.9
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.8
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.7
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.6
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.5
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.4
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.3
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.2
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0.1
			wait(0.6)
			script.Parent.ActivationPart.Transparency = 0
			script.Parent.LighteningParticleEmitters.Part.ParticleEmitter.Enabled = true
			wait(2)
			script.Parent.Core.Script.Disabled = false
			script.Parent.Shield.Transparency = 1
			wait(0.6)
			script.Parent.Shield.Transparency = 0.9
			wait(0.6)
			script.Parent.Shield.Transparency = 0.8
			wait(0.6)
			script.Parent.Shield.Transparency = 0.7
			wait(0.6)
			script.Parent.Shield.Transparency = 0.6
			wait(0.6)
			script.Parent.Shield.Transparency = 0.5
			wait(0.6)
			script.Parent.Shield.Transparency = 0.4
			wait(0.6)
			script.Parent.Shield.Transparency = 0.3
			wait(0.6)
			script.Parent.Shield.Transparency = 0.2
			wait(0.6)
			script.Parent.Shield.Transparency = 0.1
			wait(0.6)
			script.Parent.Shield.Transparency = 0
			tEnabled = false -- Disable 't'
			Enabled = true
			Button.BrickColor = BrickColor.new("Lime green")
			end
		end
	end
end

local function handleButton()
	if isActive then
		deactivate()
	else
		activate()
	end
end

local function touc(part)
	local plr = game.Players:FindFirstChild(part.Parent.Name)
	if plr then
		local h = part.Parent:FindFirstChild("Humanoid")
		if h then
			if isActive then
				if plr.Tycoon.Value and Model:FindFirstAncestor(plr.Tycoon.Value.Name) then
					
				else
					h.Health = h.Health - 10000
				end
			end
		end
	end
end

HitPart.Touched:Connect(touc)

OwnerOnlyPrompt.Triggered:Connect(function(plr)
	if plr.Tycoon.Value and Model:FindFirstAncestor(plr.Tycoon.Value.Name) then
		handleButton()
	end
end)

Code in Script3

local Part = script.Parent
Part.Color = Color3.new(0,0,0)

local TS = game:GetService("TweenService")
local Info = TweenInfo.new(12, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

TS:Create(Part, Info, {Color = Color3.new(0.0156863, 0.686275, 0.92549)}):Play()

Code in Script4

local Part = script.Parent
Part.Color = Color3.new(0.0156863, 0.686275, 0.92549)

local TS = game:GetService("TweenService")
local Info = TweenInfo.new(12, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

TS:Create(Part, Info, {Color = Color3.new(0,0,0)}):Play()
1 Like

if you want the tweens in script 3 and 4 to repeat you need to change their repeat count paramter, -1 will repeat forever