I have 2 scripts in my coin sim game and while they work fine when there’s only a few coins I’ve recently increased the amount to service the entire game. This is about 2000 coins. The 2 scripts basically use while true do to spin and hover and it’s making the game lagged when I clone the coin many times. I was thinking that maybe a runservice or something might be the key but I wanted to run it by other people before I go ahead and rewrite a dozen scripts in hopes to fix it.
bro if your spinning 2k parts your gonna lag NO MATTER WHAT
Hi! I would personally make them spin locally, when the player gets close to the coins. When that is said, you just get all parts around your player character, if the part is a coin, and is within the range you specify, then make it spin.
I suggest keeping a cache along with tortens idea
just update it every 20 seconds and whenever they use a teleporter or something
(table of close enough coins to update)
Seems to me I have far less coins than I’ve seen in other games. I shrunk it down to a number that doesn’t look too bare and removed the float script but it’s still lags. Static coins look very boring so I’m trying to jazz it up a bit as show on image.
Hi,
You should think about performance. Take a look at the Sonic game that was a Roblox event for some time ago. They have single-coins, but they’re also thoughtful placed around the map, and also only loads in when needed (I expect).
I would suggest that you make stacks of coins, like in pet simulator, and have different kind of stacks. You can even animate the stacks, so they don’t look boring aswell, and a stack can have the same amount of value as 10, 100, 1000 or even more coins.
Yeah I do have, coins, chests and diamonds and took me weeks to make all the models for the game cause I’d never used Blender before. As the player progresses the coins are worth more and more, chests spawn as the player plays the game etc. There’s a rebirth and stats system as well. I want it to feel like classic coin sim with some quality of life changes. It’s just for my learning and I want to see it completed soon so I can see and learn the whole process.
Please upload your coin model, then I can take a quick look at it. The model itself can also be a performance issue.
Did you have 2 coin script for EACH coin btw?
If that is the case, instead define where your coins is, and create a core loop that handles it all:
local Coins = .. -- Define yourself
for _, Coin in pairs(Coins) do
-- Coin touched event here
end
-- Remember to do this locally, the defined coins here should only be the ones close to the player.
-- You have to define which coins is close before doing this:
for _, Coin in pairs(Coins) do
--Coin spin event here
-- I also see that you change the orientation of the coin, in a loop.
-- Instead use a tween to change the orientation by 90 degrees each loop for example
-- This can reduce 90 tasks into 1
end
Yeah I just cloned them from server storage. Each time a coin is collected a new coin is produced and randomly placed on the map. I did this so no 1 person could clear the area and if multiple players in the same zone everyone could have access to the same amount of coins. I would prefer to have more coins than 300 in each zone to populate it a bit more but I ran into lag so I needed a new way.
I hadn’t thought of tweenservice which is exactly why I posted here so get some feedback.
I’m unsure about which impact tweens would have at that scale, but normally games do not have even near that amount of tweens active at once. It got me thinking about Triple-A games. Even in those games there is cut corners, that is quite noticeable, if you know what to look for.
Spin them locally, or use an animation to spin them. An animation probably would be far less laggy.
This seemed like a good start for me, place a coin, collect it, get money. I picked up certain events like click, touch, etc very quickly but other things like tables, datastores, and tweens etc I find very hard to understand. I learned studio in a month and was making entire residential buildings cranes, vehicles etc. Blender took me a month just to learn the keybinds for simple models. Now I’m trying to put all that together in a game and well this is where I’m at.
@okayendo I’ve not done animations before.Could you elaborate on that a bit?
I would not use RunService for this. I thought Heartbeat was the best way, but it ended up making things very laggy.
while true do
task.wait()
end
is the best method.
I’ve had to have mass amounts of currency items placed haphazardly in one game of mine, and I’ve found client-sided animations to be the best method (even better if the coins can be loaded on the client as well)
add an AnimationController to the model and add a motor6D to each part you want to move. you can then edit the object with the animation editor.
Save the animation to an animation to roblox, create an animation instance, and add the ID in there
play it on the client.
No, don’t do this.
It is best if you use TweenService if you want to move this many parts.
local TweenService = game:GetService("TweenService")
local TweenInfo = TweenInfo.new()
local Parts = -- the area where the parts are, either a model or folder.
local function MoveParts()
for _, Part in Parts do
TweenService:Create(Part, TweenInfo, {Position = Part.Position - Part.Position.Y}):Play()
end
end
-- When you are ready, add below to the code.
MoveParts()
As a few have mentioned, loading animations from the client is possibly the best approach for your case of use.
Be aware that your animation would reset each time you start them over, unless you pause your animation instead of stopping them. But I would suggest stopping them over pausing them, if you’re using this many animations.