Hello!
I got a little problem
I’m making a 4 crystals is rotating around player
Well I make it but the tween are spamming and I don’t know how to prevent it
I tried do debaunce but when I did debaunce it was tweening everyone part slower
What I’m exactly doing is magic (yep)
Well I don’t know how to fix it
So I’m asking you if you can help me
There is needed resources you need to help me
Script
The script it server script!
game.Players.PlayerAdded:Connect(function(player)
wait(5)
for _,attch in pairs(game.ServerStorage.Attachments:GetChildren()) do
local Cloned = attch:Clone()
Cloned.Parent = player.Character.HumanoidRootPart
end
local CrystalFolder = Instance.new("Folder",player.Character)
local Cry1 = game.ServerStorage.Crystal:Clone()
local Cry2 = game.ServerStorage.Crystal:Clone()
local Cry3 = game.ServerStorage.Crystal:Clone()
local Cry4 = game.ServerStorage.Crystal:Clone()
CrystalFolder.Name = "Crystals"
Cry1.Parent = CrystalFolder
Cry2.Parent = CrystalFolder
Cry3.Parent = CrystalFolder
Cry4.Parent = CrystalFolder
local did = 1
for _,crystal in pairs(CrystalFolder:GetChildren()) do
crystal.Name = "Crystal"..did
crystal.Position = player.Character.HumanoidRootPart["Crystal"..did].WorldPosition
did = did + 1
end
local IsAlreadyTweening = false
while wait(0.001) do
if IsAlreadyTweening == false then
IsAlreadyTweening = true
local did = 1
for _,crystal in pairs(CrystalFolder:GetChildren()) do
crystal.Name = "Crystal"..did
local Tween = game:GetService("TweenService"):Create(crystal,TweenInfo.new(0.3,Enum.EasingStyle.Sine,Enum.EasingDirection.In),{Position = player.Character.HumanoidRootPart["Crystal"..did].WorldPosition},false)
did = did + 1
Tween:Play()
end
IsAlreadyTweening = false
end
end
end)
I think you can use BodyMovers to achieve this effect instead of tweening. Try using BodyPositions for moving the crystals and BodyGyros for rotating them.
About why it’s not so smooth, this is probably due to replication rate. The server has to replicate the tween to every client, which makes it look not so smooth.
A good alternative would be to use the event RenderStepped + Lerp to change it very smoothly. To make it visible to everyone I recommend to use RemoteEvents and a ServerSkript. Before you ask me now, what is where who, I tell you already you should look for it instead of answering after 3 seconds.
ok that’s a random bump after 4 years, and an unexpected one not gonna lie
But I see 2 issues lerping on the client side:
lerping isn’t that smooth and to run it every single renderstep makes it cost a lot of memory/energy, which is not good in a game with multiple players
if you change it on the client’s side, you will see it yeah, but everyone else won’t see it because what the client modifies doesn’t get replicated on the server (exceptions, however, are all related to the player’s own character, like being playing animations in a local script)
So, meanwhile AlignPositions got released, I would recommend you to fire a RemoteEvent to the server (if you get the pet after buying it or just use a serverscript to begin with), and on the server’s side, create an AlignPosition (if you create it in a client script it won’t actually exist in the server’s side. Again, this is done to prevent most exploits) and set up your AlignPosition there. Pretty sure AlignPositions nowadays fix this issue on their own