It works but the script activity is so high, also if I want to move the part to another position while still moving up and down, it won’t move. It’s basically a snake game. I don’t destroy the food, instead I just move it to a random position. The food moving up and down is essentially just for the visuals. I think it is best to get it done on the client.
I have a part welded to the apple and it is spinning crazily, when the apple is spinning slowly.
local CS = game:GetService("CollectionService")
local function whileTask(Variable)
local Sine = 0
local OGCF = Variable.PrimaryPart.CFrame
while true do
task.wait()
Sine += 1 --Infinite Sinewave Num
Variable.PrimaryPart.CFrame = OGCF:Lerp(CFrame.new(0,math.sin(Sine/10)*2,0),0.25) --Lerp animation
Variable.PrimaryPart.Orientation = Vector3.new(0, Sine, 0)
end
end
for Index,Variable in pairs(CS:GetTagged("Apple")) do
task.spawn(whileTask,Variable) --Spawn task with WhileTask, pass variable Variable
end
CS:GetInstanceAddedSignal("Apple"):Connect(function(Variable)
task.spawn(whileTask,Variable) --Spawn task with WhileTask, pass variable Variable
end)