Shrine model keeps disappearing randomly

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    For the shrine model to stop disappearing early and to let the tween complete, hence completing the script
  2. What is the issue? Include screenshots / videos if possible!
    It keeps infinite yielding or attempting to index findfirstchild because the folder keeps on disappearing randomly. It works sometimes but most of the time when the tool is used, the shrine completely disappears nearing the end of it and the script completely breaks.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    yes, the built in AI beta and my scripter friend. It is a tool and the colorcorrection effect also stays when it breaks

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local CollectionService = game:GetService('CollectionService')
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("ShrineEvent")
local TweenService = game:GetService('TweenService')
local Debris = game:GetService("Debris")
local CollectionService = game:GetService('CollectionService')
local Assets = game:GetService("ReplicatedStorage"):WaitForChild("Assets")
local Setting = require(script:WaitForChild("Setting"))

local rng = math.random
local rad = math.rad
local angle = CFrame.fromEulerAnglesXYZ

Remote.OnServerEvent:Connect(function()
	local Player = script:FindFirstAncestorWhichIsA"Player" or game:GetService"Players":GetPlayerFromCharacter(script.Parent.Parent)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local Humanoid = Character:WaitForChild("Humanoid")
	local Root = Character:WaitForChild("HumanoidRootPart")

	if not CollectionService:HasTag(Character,"Attacking") and not CollectionService:HasTag(Character,"MalevolentShrineCD") then

		CollectionService:AddTag(Character,"Attacking")
		CollectionService:AddTag(Character,"MalevolentShrineCD")

		local SavedWalkSpeed = Humanoid.WalkSpeed
		local SavedJumpPower = Humanoid.JumpPower
		local SavedJumpHeight = Humanoid.JumpHeight

		local Cooldown = Setting["Cooldown"]
		local Duration = Setting["Duration"]
		local HitboxRange = Setting["HitboxRange"]
		local VisualRange = Setting["VisualRange"]
		local Damage = Setting["Damage"]
		local Moveable = Setting["Moveable"]
		local SlashPerRound = Setting["SlashPerRound"]
		local Rock = Setting["Rock"]

		local Overhead = Assets["VFX"]["Part"]["Overhead"]:Clone()
		Overhead.Parent = Root

		Humanoid.AutoRotate = false
		Humanoid.WalkSpeed = 0
		Humanoid.JumpPower = 0
		Humanoid.JumpHeight = 0

		local FXFolder = Instance.new("Folder",workspace)
		FXFolder.Name = "MalShrine"
		Debris:AddItem(FXFolder,Duration+10)

		local RockFolder = Instance.new("Folder",FXFolder)
		RockFolder.Name = "Rocks"

		local SlashesFolder = Instance.new("Model",FXFolder)
		SlashesFolder.Name = "Slashes"

		local DestroyedFolder = Instance.new("Folder",FXFolder)
		DestroyedFolder.Name = "DestroyedFolder"

		local Highlight = Instance.new("Highlight",SlashesFolder)
		Highlight.DepthMode = Enum.HighlightDepthMode.Occluded
		Highlight.FillColor = Color3.new(0, 0, 0)
		Highlight.OutlineTransparency = 1
		Highlight.FillTransparency = 0

		local Voice = Assets["SFX"]["Voice"]:Clone()
		Voice.Parent = Root
		Voice.RollOffMaxDistance = VisualRange/2
		Voice:Play()
		Debris:AddItem(Voice,Voice.TimeLength+0.2)

		local Action = Humanoid:LoadAnimation(Assets["Animations"]["Standing"])
		Action:Play(0.1,1,1)

		Action:GetMarkerReachedSignal("Stop"):Connect(function()
			Action:AdjustSpeed(0)
		end)

		task.spawn(function()

			local Hitted = {}

			local Hitbox = workspace:GetPartBoundsInBox(Root.CFrame,HitboxRange)
			for i,a in pairs(Hitbox) do
				if a.Parent:FindFirstChild("Humanoid") and a.Parent:FindFirstChild("HumanoidRootPart") then
					local Enemy = a.Parent
					local EnemyHumanoid = Enemy:FindFirstChild("Humanoid")
					local EnemyRoot = Enemy:FindFirstChild("HumanoidRootPart")
					if Hitted[EnemyHumanoid] == nil then
						Hitted[EnemyHumanoid] = true

						local IsPlayer = game:GetService("Players"):GetPlayerFromCharacter(Enemy)
						if IsPlayer then
							task.spawn(function()
								Remote:FireClient(IsPlayer,"Cutscene",{1,Character})
								task.wait(3.25)
								Remote:FireClient(IsPlayer,"Cutscene",{2,Character})
							end)
						end
					end
				end
			end
		end)

		task.wait(1)

		Overhead:Destroy()

		Root.Anchored = true

		local Shrine = Assets["VFX"]["Shrine"]:Clone()
		Shrine.Parent = FXFolder

		local Shrine2 = Shrine:WaitForChild("Shrine2", 5) -- Adding a timeout of 5 seconds
		if not Shrine2 then
			warn("Shrine2 not found within timeout!")
			return
		end

		Shrine2.OST.RollOffMaxDistance = VisualRange / 2
		Shrine2.Saw.RollOffMaxDistance = VisualRange / 2

		Shrine:SetPrimaryPartCFrame(Root.CFrame * CFrame.new(0, -20, 12))

		local Goal = {
			CFrame = Root.CFrame * CFrame.new(0,13,12)
		}
		local Info = TweenInfo.new(2,Enum.EasingStyle.Sine)
		local Tween = TweenService:Create(Shrine:WaitForChild("Shrine2"),Info,Goal)
		Tween:Play()

		local Goal = {
			CFrame = Root.CFrame * CFrame.new(0,6,0)
		}
		local Info = TweenInfo.new(2,Enum.EasingStyle.Sine)
		local Tween = TweenService:Create(Root,Info,Goal)
		Tween:Play()

		task.wait(2.25)

		local Goal = {
			FillTransparency = 1,
		}
		local Info = TweenInfo.new(1,Enum.EasingStyle.Sine)
		local Tween = TweenService:Create(Shrine.Highlight,Info,Goal)
		Tween:Play()

		task.wait(0.76)

		local Slashing = Instance.new("ColorCorrectionEffect",game.Lighting)

		local Goal = {
			Brightness = -0.3,
			Contrast = 0.2,
			TintColor = Color3.fromRGB(255, 181, 181)
		}
		local Info = TweenInfo.new(1,Enum.EasingStyle.Sine)
		local Tween = TweenService:Create(Slashing,Info,Goal)
		Tween:Play()

		Shrine:WaitForChild("Shrine2").OST:Play()
		Shrine:WaitForChild("Shrine2").Saw:Play()
		
		local SavedCF = Root.CFrame
		
		if Moveable == true then
			Humanoid.WalkSpeed = SavedWalkSpeed
			Humanoid.JumpPower = SavedJumpPower
			Humanoid.JumpHeight = SavedJumpHeight

			Action:Stop()
			Root.Anchored = false
			Humanoid.AutoRotate = true
		end

		local Start = tick()

		local DestroyedPart = {}

		repeat

			local Hitted = {}
			local Hitbox = workspace:GetPartBoundsInBox(Shrine:WaitForChild("Shrine2").CFrame,HitboxRange)
			for i,a in pairs(Hitbox) do
				if a.Parent and a.Parent:FindFirstChild("Humanoid") and a.Parent:FindFirstChild("Torso") then
					local Enemy = a.Parent
					local EnemyHumanoid = Enemy:FindFirstChild("Humanoid")
					local EnemyRoot = Enemy:FindFirstChild("Torso")
					if Hitted[EnemyHumanoid] == nil then
						Hitted[EnemyHumanoid] = true

						if Enemy ~= Character then
							EnemyHumanoid:TakeDamage(Damage)
						end

						local IsPlayer = game:GetService("Players"):GetPlayerFromCharacter(Enemy)
						if IsPlayer then
							Remote:FireClient(IsPlayer,"CameraShake",{4,50,0,0.15})
						end
					end
				end
				if a:IsA("BasePart") and CollectionService:HasTag(a,"Destroyable") and not CollectionService:HasTag(a,"Regen") then
					if not DestroyedPart[a] and not a:IsDescendantOf(DestroyedFolder) then
						DestroyedPart[a] = {
							["Part"] = a,
							["Parent"] = a.Parent,
							["Transparency"] = a.Transparency,
						}
					end

					if a.Size.X >= 1 and a.Size.Y >= 1 and a.Size.Z >= 1 then
						local Cloned = a:Clone()
						Cloned.Parent = DestroyedFolder
						Cloned.Size = Vector3.new(a.Size.X/1.1,a.Size.Y/1.1,a.Size.Z/1.1)
						Cloned.CFrame = a.CFrame
						Cloned.Anchored = false
						Cloned.CanCollide = true
					end

					a:Destroy()

				end
			end

			for i = 1,SlashPerRound do
				Remote:FireAllClients("Slashes",{
					["Parent"] = SlashesFolder,
					["CFrame"] = Shrine:WaitForChild("Shrine2").CFrame * CFrame.new(rng(-VisualRange/2,VisualRange/2),0,rng(-VisualRange/2,VisualRange/2)) * CFrame.fromEulerAnglesXYZ(rng(-180,180),0,rng(-180,180)),
				})
			end
			
			local Divined = 1
			
			if Rock == 2 then
				Divined = 1
			elseif Rock == 1 then
				Divined = 2
			end
			
			if Rock ~= 0 then
				Remote:FireAllClients("RayCastRock",{
					["User"] = Character,
					["Type"] = "PebbleFly",
					["Loop"] = rng(10,15)/Divined,
					["Parent"] = RockFolder,
					["DespawnTime"] = 1,
					["DelayTime"] = 3,
					["Part"] = Shrine:WaitForChild("Shrine2"),
					["Force"] = rng(40,100),
					["RayCast"] = {
						["RayRange"] = -20,
						["RayDistanceAway"] = VisualRange/2,
						["RaySize"] = Vector3.new(rng(2,5),rng(2,5),rng(2,5)),
					},
				})

				Remote:FireAllClients("RayCastRock",{
					["User"] = Character,
					["Type"] = "PebbleFly",
					["Loop"] = rng(15,20)/Divined,
					["Parent"] = RockFolder,
					["DespawnTime"] = 1,
					["DelayTime"] = 3,
					["Part"] = Shrine:WaitForChild("Shrine2"),
					["Force"] = rng(60,120),
					["RayCast"] = {
						["RayRange"] = -20,
						["RayDistanceAway"] = VisualRange/2,
						["RaySize"] = Vector3.new(1,1,1),
					},
				})
			end
			
			if Humanoid.Health <= 0 or Character.Parent == nil then
				break
			end

			task.wait(0.05)

		until tick() - Start >= Duration

		CollectionService:RemoveTag(Character,"Attacking")

		Debris:AddItem(FXFolder,16)

		DestroyedFolder:Destroy()

		task.delay(10,function()
			for i, a in pairs(DestroyedPart) do
				local Cloned = a.Part:Clone()
				Cloned.Transparency = 1
				Cloned.Parent = a.Parent

				CollectionService:AddTag(Cloned,"Regen")

				local Goal = {
					Transparency = a.Transparency,
				}
				local Info = TweenInfo.new(1,Enum.EasingStyle.Sine)
				local Tween = TweenService:Create(Cloned,Info,Goal)
				Tween:Play()
				Tween.Completed:Connect(function()
					CollectionService:RemoveTag(Cloned,"Regen")
				end)
			end
		end)

		if Moveable == false then
			Humanoid.WalkSpeed = SavedWalkSpeed
			Humanoid.JumpPower = SavedJumpPower
			Humanoid.JumpHeight = SavedJumpHeight

			Action:Stop()
			Root.Anchored = false
			Humanoid.AutoRotate = true
		end

		Shrine:WaitForChild("Shrine2").Saw:Stop()

		local Goal = {
			Brightness = 0,
			Contrast = 0,
			TintColor = Color3.fromRGB(255, 255, 255)
		}
		local Info = TweenInfo.new(1,Enum.EasingStyle.Sine)
		local Tween = TweenService:Create(Slashing,Info,Goal)
		Tween:Play()
		Tween.Completed:Connect(function()
			Slashing:Destroy()
		end)

		Shrine.Highlight.FillColor = Color3.fromRGB(0, 0, 0)
		local Goal = {
			OutlineTransparency = 0,
			FillTransparency = 0,
		}
		local Info = TweenInfo.new(2,Enum.EasingStyle.Sine)
		local Tween = TweenService:Create(Shrine.Highlight,Info,Goal)
		Tween:Play()

		for _, part in pairs(Shrine:GetDescendants()) do
			if part:IsA("BasePart") then
				part.CanCollide = false
			end
		end

		local Goal = {
			Volume = 0
		}
		local Info = TweenInfo.new(1,Enum.EasingStyle.Sine)
		local Tween = TweenService:Create(Shrine:WaitForChild("Shrine2").OST,Info,Goal)
		Tween:Play()

		local Goal = {
			CFrame = SavedCF * CFrame.new(0, -30, 12)
		}
		local Info = TweenInfo.new(2, Enum.EasingStyle.Sine)
		local Tween = TweenService:Create(Shrine2, Info, Goal)
		Tween:Play()
		Tween.Completed:Connect(function()
			task.wait(1)
			Shrine:Destroy()
		end)

		task.delay(Cooldown, function()
			CollectionService:RemoveTag(Character, "MalevolentShrineCD")
		end)

	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

please highlight the code where the error appears

Its all of the line of code which asks for the Shrine2 model, It just disappears without any error.
image

Don’t know if this might be related, but the LocalScript in ReplicatedFirst that handles VFX

script.Parent = nil

local TweenService = game:GetService('TweenService')
local Debris = game:GetService("Debris")
local RS = game:GetService("ReplicatedStorage")
local CameraShake = require(RS:WaitForChild("Modules").CameraShaker) -- If your game already have CameraShaker[sleitnick] change the path of this line.
local CurrectCamera = workspace.CurrentCamera
local CamShake = CameraShake.new(Enum.RenderPriority.Camera.Value, function(Cf)
	CurrectCamera.CFrame *= Cf
end)
CamShake:Start()

local rng = math.random
local rad = math.rad
local angle = CFrame.fromEulerAnglesXYZ

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("ShrineEvent")

local StoredInstance = {}

Remote.OnClientEvent:Connect(function(Event,...)
	if Event == "RayCastRock" then
		local ArgTable = (...)
		local User = ArgTable["User"]
		local Type = ArgTable["Type"]
		if Type == "Round" then
			local Loop = ArgTable["Loop"]
			local Part = ArgTable["Part"]
			local UpTime = ArgTable["UpTime"]
			local DownTime = ArgTable["DownTime"]
			local DelayTime = ArgTable["DelayTime"]
			local RayCastInfo = ArgTable["RayCast"]
			local RayRange = RayCastInfo["RayRange"]
			local RayDistanceAway = RayCastInfo["RayDistanceAway"]
			local RaySize = RayCastInfo["RaySize"]
			local Folder = Instance.new("Folder",workspace)
			Folder.Name = "Rocks"
			local Param = RaycastParams.new()
			Param.FilterDescendantsInstances = {User,workspace.Terrain}
			Param.FilterType = Enum.RaycastFilterType.Exclude

			local Rotate = 0
			local CalAngle = 360/Loop

			for i = 1,Loop do
				local Rock = Instance.new("Part")
				Rock.Size = RaySize
				Rock.CFrame = Part.CFrame * angle(0,rad(Rotate),0) * CFrame.new(0,0,RayDistanceAway)
				Rock.Anchored = true

				local RayCast = workspace:Raycast(Rock.CFrame.Position,Rock.CFrame.UpVector * RayRange,Param)
				if RayCast then
					local HitPart = RayCast.Instance
					Rock.Position = RayCast.Position - Vector3.new(0,RaySize.Y,0)
					Rock.Parent = Folder
					Rock.CFrame = CFrame.lookAt(Rock.Position,Part.Position)
					Rock.Color = HitPart.Color
					Rock.Orientation = Rock.Orientation + Vector3.new(0,rng(-10,10),rng(-10,10))
					Rock.Material = HitPart.Material
					for _,A in pairs(HitPart:GetChildren()) do
						if A:IsA("Texture") or A:IsA("Decal") then
							local Clone = A:Clone()
							Clone.Parent = Rock
						end
					end
					local Goal = {
						Position = Rock.Position + Vector3.new(0,RaySize.Y - 0.5,0)
					}
					local Info = TweenInfo.new(UpTime,Enum.EasingStyle.Sine)
					local Tween = TweenService:Create(Rock,Info,Goal)
					Tween:Play()
					Tween.Completed:Connect(function()
						task.wait(DelayTime)
						Rock.CanCollide = false
						local Goal = {
							Position = Rock.Position - Vector3.new(0,RaySize.Y,0),
						}
						local Info = TweenInfo.new(DownTime,Enum.EasingStyle.Sine)
						local Tween = TweenService:Create(Rock,Info,Goal)
						Tween:Play()
						Tween.Completed:Connect(function()
							Debris:AddItem(Folder,1)
						end)
					end)
				end
				Rotate += CalAngle
			end
		elseif Type == "PebbleFly" then
			local Loop = ArgTable["Loop"]
			local Parent = ArgTable["Parent"]
			local Part = ArgTable["Part"]
			local Force = ArgTable["Force"]
			local DespawnTime = ArgTable["DespawnTime"]
			local DelayTime = ArgTable["DelayTime"]
			local RayCastInfo = ArgTable["RayCast"]
			local RayRange = RayCastInfo["RayRange"]
			local RayDistanceAway = RayCastInfo["RayDistanceAway"]
			local RaySize = RayCastInfo["RaySize"]
			local Param = RaycastParams.new()
			Param.FilterDescendantsInstances = {User,workspace.Terrain}
			Param.FilterType = Enum.RaycastFilterType.Exclude

			for i = 1,Loop do
				local Rock = script:WaitForChild("RayCastRock")["Pebble"]:Clone()
				Rock.Size = RaySize
				Rock.CFrame = Part.CFrame * angle(rad(rng(-30,30)),0,rad(rng(-30,30))) * CFrame.new(rng(-RayDistanceAway,RayDistanceAway),0,rng(-RayDistanceAway,RayDistanceAway))
				Rock.Anchored = true

				local RayCast = workspace:Raycast(Rock.CFrame.Position,Rock.CFrame.UpVector * RayRange,Param)
				if RayCast then
					local HitPart = RayCast.Instance
					Rock.Anchored = false
					Rock.Position = RayCast.Position - Vector3.new(0,1,0)
					Rock.Parent = Parent
					Rock.Color = HitPart.Color
					Rock.Material = HitPart.Material
					Rock.CanCollide = false
					for _,A in pairs(HitPart:GetChildren()) do
						if A:IsA("Texture") or A:IsA("Decal") then
							local Clone = A:Clone()
							Clone.Parent = Rock
						end
					end
					local Linear = Instance.new("LinearVelocity",Rock)
					Linear.Attachment0 = Rock["Liner"]
					Linear.MaxForce = 1*80000
					Linear.VectorVelocity = Rock.CFrame.UpVector * Force
					task.delay(0.1,function()
						Rock.CanCollide = true
						Debris:AddItem(Linear,1)
						task.wait(DelayTime)
						local Goal = {
							Size = Vector3.new(0,0,0),
						}
						local Info = TweenInfo.new(DespawnTime,Enum.EasingStyle.Sine)
						local Tween = TweenService:Create(Rock,Info,Goal)
						Tween:Play()
						Tween.Completed:Connect(function()
							Debris:AddItem(Rock,1)
						end)
					end)
				end
			end
		end
	elseif Event == "EmitParticle" then
		local ArgTable = (...)
		local Particle = ArgTable[1]
		local Emit = ArgTable[2]
		Particle:Emit(Emit)
	elseif Event == "CameraShake" then
		local ArgTable = (...)
		local Magnitude = ArgTable[1]
		local Roughness = ArgTable[2]
		local FadeIn = ArgTable[3]
		local FadeOut = ArgTable[4]
		CamShake:ShakeOnce(Magnitude,Roughness,FadeIn,FadeOut)
	elseif Event == "Cutscene" then
		local ArgTable = (...)
		local Part = ArgTable[1]
		if Part == 1 then
			
			local Caster = ArgTable[2]
			
			StoredInstance[Caster] = {}
			
			local highlight = Instance.new('Highlight',Caster)
			highlight.FillColor = Color3.new(1, 1, 1)
			highlight.OutlineColor = Color3.new(0, 0, 0)
			highlight.FillTransparency = 1
			highlight.OutlineTransparency = 1
			highlight.DepthMode = Enum.HighlightDepthMode.Occluded
			highlight.Name = "HighlightFrame"
			
			local Goal = {
				FillTransparency = 0,
				OutlineTransparency = 0,
			}
			local Info = TweenInfo.new(1,Enum.EasingStyle.Sine)
			local Tween = TweenService:Create(highlight,Info,Goal)
			Tween:Play()
			
			local Blackout = Instance.new("ColorCorrectionEffect",game.Lighting)
			Blackout.Name = "Blackout"
			local Goal = {
				Brightness = -2,
			}
			local Info = TweenInfo.new(1,Enum.EasingStyle.Sine)
			local Tween = TweenService:Create(Blackout,Info,Goal)
			Tween:Play()
			
			StoredInstance[Caster]["Highlight"] = highlight
			StoredInstance[Caster]["Blackout"] = Blackout
			
		elseif Part == 2 then
			local Caster = ArgTable[2]
			local Blackout = StoredInstance[Caster]["Blackout"]
			if Blackout then
				local Goal = {
					Brightness = 0,
				}
				local Info = TweenInfo.new(0.5,Enum.EasingStyle.Sine)
				local Tween = TweenService:Create(Blackout,Info,Goal)
				Tween:Play()
				Tween.Completed:Connect(function()
					Blackout:Destroy()
				end)
			end
			local HighligthFrame = StoredInstance[Caster]["Highlight"]
			local Goal = {
				FillTransparency = 1,
				OutlineTransparency = 1,
			}
			local Info = TweenInfo.new(1,Enum.EasingStyle.Sine)
			local Tween = TweenService:Create(HighligthFrame,Info,Goal)
			Tween:Play()
			Tween.Completed:Connect(function()
				HighligthFrame:Destroy()
			end)
		end
	elseif Event == "Slashes" then
		local ArgTable = (...)
		local Parent = ArgTable["Parent"]
		local CFrameSet = ArgTable["CFrame"]
		local Slash = script["Slashing"]:Clone()
		Slash.Parent = Parent
		Slash.CFrame = CFrameSet
		Slash.Size = Vector3.new(rng(100,200),1,1)
		local Goal = {
			Size = Vector3.new(Slash.Size.X,0,0),
		}
		local Info = TweenInfo.new(0.3,Enum.EasingStyle.Sine)
		local Tween = TweenService:Create(Slash,Info,Goal)
		Tween:Play()
		Tween.Completed:Connect(function()
			Slash:Destroy()
		end)
	
	end
end)
2 Likes

Update: it only breaks if another person uses it too