Optimization animation of a sign

Hello, when I enable this “animation” I have not a lot of FPS but I do not know how can I improve it.
I want to do this : https://gyazo.com/5a9a25bf40494a785e1fc9f5e4265327

I use 2 local scripts : 1 for the move and 1 for the light :

local signs = workspace.Signs

local FromCityToBorder_SIGN = signs.FromCityToBorder

local function updatePart(part)
	part.Material = Enum.Material.Neon
	for i = 0.8, 0, -0.1 do 
		part.Transparency = i
		task.wait(0.05)
	end
	task.wait(0.2)
	part.Material = Enum.Material.ForceField
end

while task.wait(1) do 
	for i = 1, 3, 1 do 
		updatePart(FromCityToBorder_SIGN:FindFirstChild("Base"..tostring(i)))
	end
	updatePart(FromCityToBorder_SIGN:FindFirstChild("Arrow_Sign"))
end
local signs = workspace.Signs

local FromCityToBorder_SIGN = signs.FromCityToBorder

local function moveslowly(model, newModelPos) 
	local old_y = model.PrimaryPart.CFrame.Y
	
	for i = model.PrimaryPart.CFrame.Y, newModelPos, 0.01 do 
		model:SetPrimaryPartCFrame(CFrame.new(model.PrimaryPart.CFrame.X, i, model.PrimaryPart.CFrame.Z) * CFrame.Angles(0, math.rad(90), 0))
		task.wait(0.01)
	end

	for i = model.PrimaryPart.CFrame.Y, old_y, -0.01 do 
		model:SetPrimaryPartCFrame(CFrame.new(model.PrimaryPart.CFrame.X, i, model.PrimaryPart.CFrame.Z) * CFrame.Angles(0, math.rad(90), 0))
		task.wait(0.01)
	end
end

while task.wait() do 
	moveslowly(FromCityToBorder_SIGN, FromCityToBorder_SIGN.Step2.CFrame.Y)
	moveslowly(FromCityToBorder_SIGN, FromCityToBorder_SIGN.Step3.CFrame.Y)
end

image
image

2 Likes

You could just use Animation Editor in Studio instead of scripting the animation.

Maybe that would help.

1 Like

Idk if it’s very useful to use with an humanoid :/.

And in your idea, how do I disable damages on it?

You can just insert an Animation Controller and you won’t need a humanoid.

1 Like

Here is a couple of things you can do.

I Recommend that you swap out :GetPrimaryPartCFrame() and :SetPrimaryPartCFrame() with :GetPivot() and :PivotTo(), :GetPrimaryPartCFrame() and :SetPrimaryPartCFrame() have been deprecated for a while now, and was superceded by :GetPivot() and PivotTo()

One thing you can do is use math.sin() to have the Platform move more smoothly on the Y axis, Its recommended that you use something like tick(), os.time() or os.clock() (i will refer to these as time) to keep the Object Constantly Moving, you can edit the speed of time, Divide it to make it slower, or Multiply it to make it faster, Here is Example Code of what I mean:

local baseCFrame = object:GetPivot() -- The Normal CFrame of the Object so we can Reference it later
local speedModifier = 1 -- the Speed Modifier for our Object

while task.wait() do -- I recommend that you use RunService Instead, as it may be more efficient
    local currentTime = os.clock()*speedModifier -- the time influenced by the speed modifier
    object:PivotTo(baseCFrame * CFrame.new(0, math.sin(currentTime), 0)) -- Moves the Object using BaseCFrame plus Modified time
    -- you can also Modify how far it goes up and down by multiplying math.sin
end

image
Yeah but I need Motor6D?

Model.rbxl (41.2 KB)

Here is a sample file to help.

There is a RootPart and a another part that has the Motor6D.

Everything in your model should weld to the WeldToMe part.

local signs = workspace.Signs

local FromCityToBorder_SIGN = signs.FromCityToBorder
local FromCityToBorder_ANIM = script.FromCityToBorder

while task.wait(0.36) do 
	local controller = FromCityToBorder_SIGN:FindFirstChild("AnimationController"):FindFirstChild("Animator")
	local anim = controller:LoadAnimation(FromCityToBorder_ANIM)
	anim:Play()
end

image

No animation is playing.

You have to write a script to tell the animation to play.

Did you read my code ??? I am calling the animation.

local anim = controller:LoadAnimation(FromCityToBorder_ANIM) anim:Play()

local FromCityToBorder_SIGN = script.Parent
local FromCityToBorder_ANIM = script.FromCityToBorder

while task.wait(0.36) do 
	local controller = FromCityToBorder_SIGN.AnimationController.Animator
	local anim = controller:LoadAnimation(FromCityToBorder_ANIM)
	print(anim.IsPlaying)
	anim:Play()
	print(anim.IsPlaying)
end

https://gyazo.com/3e70143a3914703a3ef0faf8aef8532b

https://gyazo.com/f9a740af7a78fefd75d615d63ab4820e

Sorry I’m doing a bunch of things at once.

You don’t need a while loop to play an animation.

It will play until you tell it to stop. (If you have loop turned on in the animation when you published it.)

1 Like

Yeah but it does not matter, it does not fix the problem in any case.

Your script just need to be:

local animation = Instance.new(“Animation”)

animation.AnimationId = “http://www.roblox.com/asset/?id=507771019” – Roblox dance emote

local animationTrack = humanoid:LoadAnimation(animation)

animationTrack:Play()

If it is not playing then check to make sure it plays inside the Animation Editor.

Also check that your animation is set to Movement when you publish and that Loop (click the symbol) is turned on.

2 Likes

It’s the CURRENT SCRIPT… You know what my code is doing or not???

Ok thank you for your help, I found the problem :).

I added Weld in different parts before add Motor6D and forgot to remove it, thank you so much for your idea and have a nice day man :).

Glad to hear it.

Sorry for doing too many things at once.

I’m glad it worked out.

1 Like

No problem man, and thanks again :>.