Hi! the title says it all, I’ve seen some posts but none of them clarified my doubt exactly.
I’m making a game that has “coins” scattered around the map (a lot), and I want to know how to make them spin without lag.
Can anyone help?
Hi! the title says it all, I’ve seen some posts but none of them clarified my doubt exactly.
I’m making a game that has “coins” scattered around the map (a lot), and I want to know how to make them spin without lag.
Can anyone help?
i think it’s the amount of parts in the coin models that are all moving around which stacks up with the more there are, you can either make the spinning client sided and optimize the spinning based on the player’s connection (by getting the duration of their render steps) to balance performance
like reygenne1 said you should move it to the client and make sure it runs on a singular loop that iterates over all coin instances and rotates it for the maximum performance (you can also optimize it further by not processing the coins that the player is too far too see using magnitude checks)
you want to spin them on the client side so the positions of the coins are not sent over the network
something like this
-- server script
while true do
-- clone a coin (make sure the coin is anchoed)
local clone = game.ServerStorage.Coin:Clone()
-- position it randomly
clone.Position = Vector3.new(math.random(-100, 100), 4, math.random(-100, 100))
-- parent the coin into the coins folder
clone.Parent = game.Workspace.Coins
-- wait 5 seconds before spawning the next coin
task.wait(5)
end
-- localscript inside replicatedfirst or starter player scripts
local runService = game:GetService("RunService")
local coinFolder = game.Workspace:WaitForChild("Coins")
local rotateSpeed = 1
runService.Heartbeat:Connect(function(deltaTime)
for i, child in ipairs(coinFolder:GetChildren()) do
child.CFrame *= CFrame.fromOrientation(0, rotateSpeed * deltaTime, 0)
end
end)
local RunService = game:GetService('RunService')
local Coins = workspace.CoinsFolder:GetChildren()
local SPIN_VELOCITY = 1
local function step()
local CFrames = {}
for _,Coin in pairs(Coins) do
table.insert(CFrames,Coin.CFrame * CFrame.new(0,SPIN_VELOCITY,0))
end
workspace:BulkMoveTo(Coins,CFrames,Enum.BulkMoveMode.FireCFrameChanged)
end
RunService:BindToRenderStep('CoinSpin',Enum.RenderPriority.Last.Value + 1,step)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.