Tween not working when model is cloned from ReplicatedStorage

The tweening script works fine if the model is in workspace but when it is in replicated storage and cloned by a local script to workspace, it does nothing. I have tried searching it up but nothing seems to work, I even tried disabling the script and re-enabling it when the model gets cloned.

Script:

workspace.DescendantAdded:WaitForChild("Star")
print("Start")

local Colors = {BrickColor.new("Pastel yellow").Color, BrickColor.new("Cool yellow").Color, BrickColor.new("Daisy orange").Color, BrickColor.new("Bright yellow").Color, BrickColor.new("New Yeller").Color, BrickColor.new("Deep orange").Color} 

local TweenService = game:GetService("TweenService")

local function ColorChange(ColorToChangeTo)
	
	print("Function on")
		
	local Union = script.Parent
		
	local tweenInfoColor = TweenInfo.new(.9,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
	local ColorProperty = {}

	ColorProperty.Color = ColorToChangeTo
	
	local tween = TweenService:Create(Union,tweenInfoColor,ColorProperty)
	tween:Play()		
	print("Tween playing")
				
	wait(.9)
				
end

							
while true do	
		
	for i,v in ipairs(Colors) do
				
		ColorChange(v)		
	
	end
		
end	

It is located in:

well thats the main problem youre cloning using a local script and the tween script is a server script. since filtering enabled is in place “actions made by the client will no longer freely replicate to the server”.
a fix to this would be using a module script and calling it via local script. or when you use remoteevent/function to fire/invoke to server and let the server clone and insert the model from replicatedstorage into workspace.

Oh, I will make a remote event and see if that works.

1 Like

The event is firing in the local script but the server script is still not working, I don’t know why.

could you elaborate on what you did?
-is the remote event firing from localscript to server and printing something?
-the codes of the serverscript and the localscript
-is the descendant “Star” being added?

workspace.DescendantAdded:WaitForChild("Star") --is it?

Sure I can.

The remote event is firing from the local script and printing something. If the remote event is fired, the local script will print("Fired successfully")

Server Side Code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local changer = ReplicatedStorage:WaitForChild("ColorChanger")
print("Remote event obtained")

changer.OnServerEvent:Connect(function()
	print("Start")
	
	local Colors = {BrickColor.new("Pastel yellow").Color, BrickColor.new("Cool yellow").Color, BrickColor.new("Daisy orange").Color, BrickColor.new("Bright yellow").Color, BrickColor.new("New Yeller").Color, BrickColor.new("Deep orange").Color} 
	

	local TweenService = game:GetService("TweenService")
		
	local function ColorChange(ColorToChangeTo)	
		print("Function on")
		
		local Union = script.Parent
			
		local tweenInfoColor = TweenInfo.new(.9,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
		local ColorProperty = {}
		
		ColorProperty.Color = ColorToChangeTo
		
		local tween = TweenService:Create(Union,tweenInfoColor,ColorProperty)
		tween:Play()		
		print("Tween playing")	
				
			wait(.9)				
		
	end	
							
	
	while true do	
						
		for i,v in ipairs(Colors) do
											
			ColorChange(v)		
				
		end
			
	end
	
end)

Local Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local arrow = ReplicatedStorage:WaitForChild("Arrow")
local changer = ReplicatedStorage:WaitForChild("ColorChanger")
local star = ReplicatedStorage:WaitForChild("Star")


arrow.OnClientEvent:Connect(function()
	local player = game.Players.LocalPlayer
	if workspace:FindFirstChild("Star") == nil then
		local cloneStar = star:Clone()
		cloneStar.Parent = game.Workspace
		changer:FireServer()
		print("Fired Successfully")
		

		while true do			
			wait(.1)				
			local level = player:WaitForChild("leaderstats").Level.Value		
			if level == script.Levels.Value then					
				cloneStar:Destroy()	
			end	
			if game.Workspace.Checkpoints:FindFirstChild(level + 1) then
				local ls = game.Workspace.Checkpoints:FindFirstChild(level + 1)
				if cloneStar.PrimaryPart then
					cloneStar:SetPrimaryPartCFrame(CFrame.new(ls.Position + Vector3.new(0,13.5,0)))
				end	
			end	
		end
	end
end)

I took out the DescendantAdded to see if it would work but it didn’t make a difference.

you’re still cloning the star inside the localscript… :l
of course this wouldnt work.

when you call changer:FireServer();
the serverscript should do the

local cloneStar = game.ReplicatedStorage:WaitForChild('Star'):Clone();
cloneStar.Parent = game.Workspace;
-- and then the tweening functions, etc etc

not the localscript

That is gonna mess up the whole script.

It works but for some reason the cloneStar:SetPrimaryPartCFrame is bugging out now.

if ur setting the setprimarypartcframe inside a severscript and if any localscript changes the position of the checkpoints then its gonna be inconsistent with the server and client (this is true vice-versa).

also like i said u can instead of using serverscript u could use localscripts instead but the “ColorChangingScript” would also have to be a module/localscript and called locally.
and yes u would have to change a lot of stuff u wrote for it to work the way u intended it to.
this is why good code design is important :slight_smile:

I just want to get this to work by the weekend some I am willing to try anything :sweat_smile: But no serverscript is changing the position of the checkpoints, I will send you a video of what happens exactly.

In this clip, it shows you the position that the Star is in when the game now starts.
https://gyazo.com/53d6a418defc59c107e5877f8f2a6512

After a little while, this happens:
https://gyazo.com/899d88794bb1e2af0471d6739802ed3e

from the gifs it has nothing to do with the tweening. this is entirely a different issue separate from tweening.

most likely theres issues with the weld/force being applied to your star motor or some script acting on it. i cant pinpoint the exact cause of the problem since i do not have enough resources to do so.

Is there anyway that the server script could find the cloned model in workspace?? Instead of me having to clone the model on the server script, it works better on the client and I want each player to see their own arrow as well as see the colour change.

Figured it out, I just changed it into a local script.