Error when cloning objects

Hi, I get an error with this script, I am confused how it happens:
Maximum event re-entrancy depth exceeded for ScriptContext.Error

Script timeout: exhausted allowed execution time

The script was also working fine earlier, I had changed it but I got the old script in history and it still seems to crash my game. Also the error is coming from
local tsunami = originalTsunami:Clone()
local tsunamiLadder = originalTsunamiLadder:Clone()

local function giveTsunami()
print("You received a Tsunami")
	workspace.Sounds.Sound.Volume = 0
	workspace.Sounds.Tsunami:Play()
	-- Get the Tsunami and TsunamiLadder models from ReplicatedStorage
	local originalTsunami = game:GetService("ReplicatedStorage"):FindFirstChild("Tsunami")
	local originalTsunamiLadder = game:GetService("ReplicatedStorage"):FindFirstChild("TsunamiLadder")

	if not originalTsunami or not originalTsunamiLadder then
		print("Could not find Tsunami or TsunamiLadder model in ReplicatedStorage")
		return
	end

	-- Clone the models
	local tsunami = originalTsunami:Clone()
	local tsunamiLadder = originalTsunamiLadder:Clone()

	-- Parent the cloned models to workspace
	tsunami.Parent = workspace
	tsunamiLadder.Parent = workspace
	
	-- Create the Tween for the Tsunami's movement
	local tweenInfo = TweenInfo.new(
		60, -- Duration
		Enum.EasingStyle.Linear, -- EasingStyle
		Enum.EasingDirection.Out, -- EasingDirection
		0, -- RepeatCount
		false, -- Reverses
		0 -- DelayTime
	)
	local tweenGoal = {Position = tsunami.Position + Vector3.new(0, 0, 450)}
	local tween = TweenService:Create(tsunami, tweenInfo, tweenGoal)

	-- Start the Tween
	tween:Play()

	-- Wait for 60 seconds then remove the Tsunami and the ladder
	wait(60)
	workspace.Sounds.Sound.Volume = 0.5
	workspace.Sounds.Tsunami:Stop()
	tsunami:Remove()
	tsunamiLadder:Remove()
	
end
2 Likes

How is giveTsunami being called. Usually this error is due to a loop or recursive function, but you don’t have either of these in the snippet shown.

1 Like

Changing:

tsunami:Remove()
tsunamiLadder:Remove()

to

tsunami:Destroy()
tsunamiLadder:Destroy()

Makes any difference? as a post I saw:

  • Remove sets the parent to nil.
  • Destroy sets the parent to nil, disconnects all connections on the object’s events, and locks the parent property.
1 Like

ive figured out the problem, its because there are scripts in the model being cloned, and that breaks it so yeah

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.