Cloned script not working

Hello, I am cloning trying to clone a script that is located in ReplicatedStorage to a character using a local script. It is cloning, but the script isn’t working.

Note: The script does work, just not after cloned.

Local Script:

local NameBox = script.Parent:WaitForChild("NameBox")
local NameButton = script.Parent:WaitForChild("NameButton")

local Text1 = ""

local player = game.Players.LocalPlayer

NameButton.MouseButton1Click:Connect(function()
	
	Text1 = tostring(NameBox.Text)
	
	local UserId = game:GetService("Players"):GetUserIdFromNameAsync(Text1)
	
	if UserId then
		
		local Model = game:GetService("Players"):CreateHumanoidModelFromUserId(UserId)
		
		if Model then
			
			for i, v in pairs(workspace:WaitForChild("Player1"):GetChildren()) do
				v:Destroy()
			end
			
			local Animator = Instance.new("Animator")
			Animator.Parent = Model:WaitForChild("Humanoid")
			
			local AnimationScript = game.ReplicatedStorage:WaitForChild("AnimationScript"):Clone()
			AnimationScript.Disabled = false
			AnimationScript.Parent = Model
			print(AnimationScript.Parent)
			
			Model.PrimaryPart = Model:WaitForChild("HumanoidRootPart")
			Model.PrimaryPart.CFrame = CFrame.new(0, 4, -10)
			Model.PrimaryPart.Orientation = Vector3.new(0, 180, 0)
			Model.PrimaryPart.Anchored = true
			Model:WaitForChild("Humanoid").DisplayDistanceType = "None"
			Model.Parent = workspace:WaitForChild("Player1")
			
			
		end
	end
end)

Basically, what this is doing is when a player types a username in a text box and clicks/taps enter, the character loads into the game.

The part I’m focused on is the AnimationScript part or the script where I clone the script that is located in ReplicatedStorage.

AnimationScript:

local Players = game:GetService("Players")

local localPlayer = workspace:WaitForChild("Player1"):WaitForChild("Player")

local Animations = game.ReplicatedStorage:WaitForChild("Animations"):GetChildren()

while not localPlayer do wait() end

local character = localPlayer
local humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")

while wait(math.random(1, 2)) do
	local RandomId = Animations[math.random(1, #Animations)]

	animation.AnimationId = "rbxassetid://"..RandomId.Value

	local animationTrack = humanoid:LoadAnimation(animation)

	animationTrack:Play()
	wait(2)
	animationTrack:Stop()
end

One this to note is that the character loaded is always named “Player”.

As always, any and all help is greatly appreciated!

1 Like

Because cloning it doesnt activate it. Use a remote EVENT when cloning to activate the other. Ex. game.ReplicatedStorage.Script:Clone()

— do what ever you want here.

game.ReplicatedStorage.Event:FireServer()

If you mean if you activate it after and it does not work, im not sure if you can even do that.