I’m trying to create smooth, seamless purchasing for my tycoon. I also want there to be animation of the items building. However, my problem is what I am doing at the moment isn’t “seamless” and just looks terrible from the player’s point of view.
What I do when a player joins is copy all objects, delete originals and store them in a table on the server. When ap layer buys the item, the item appears on the server. I then use a .ChildAdded on the client to detect when an item has been added, and then I can do the loading in animation.
However, I NEED to use a wait() after the ChildAdded, as for some reason the model gets added, but all its children arent loaded in the same instance.
As you can see, the item appears, then disappears to do the animation
-- Server (on button touched)
local ItemValue = button.Item.Value
local Item = items[ItemValue]
Item.Model.Parent = Item.Folder
-- Client
for _, v in pairs(PlayersTycoon.Items:GetChildren()) do
v.ChildAdded:Connect(function(model)
wait()
coroutine.wrap(function()
Animation(model)
end)()
end)
end
So how can I get it to be instant, so it loads in fully on the server, but the client does the whole animation before it appears on their screen
To my understanding you’re saying your issue is that you can see the entire model for a slight second before the animation plays. In that case you can probably use PreloadAsync() to load the models assets before starting the animation.
@AstrealDev Solution as shown below may work as well by setting the parts transparency to 1 but that doesn’t stop the animation playing before the parts load.
So one solution is to handle the animation on the server. I see why you’re handling on the client since it’s resource intensive and doesn’t matter if other players see it but this is the first solution. Another solution is to use transparency before you parent & after but this can get really complicated.
Yeah that’s why I was saying it could get complicated. The workaround would be sending a request to a RemoteFunction from server → client after transparency is set to 1 then wait for a response (some value gets returned) which will happen after the animations get played. After that then the server can set the transparency back to 0. The problem with this is now there’s a delay between when the player steps on the buy button and between when it shows up on the server for everyone else.
Whilst writing this I realised that your animation involves tweening the transparency from 1. As such, store the objects as transparent on the server - you shouldn’t need to change your code for this. You can even use the code snippet in the Old Answer below to do this when the game starts, so you don’t have to fiddle around with transparency whenever you change a model
(I may have misunderstood the issue, if the actual issue is “I can’t tell when the model has loaded fully to begin the animation”, in which case: have the parts animate in nicely on the client, then have them load in bog standard on the server, then delete the parts on the client. The user shouldn’t see a difference)
Old Answer
I don’t see how it would be complicated, but it could make the initial load-in more resource intensive.
I haven’t got access to Roblox Studio right now to test it, but this script should recursively set the transparency of a model:
function recursiveTransparent(model, targetTransparency)
local children = instance:GetChildren()
if #children == 0 then
return
end
for _, v in ipairs(instance:GetChildren()) do
if v:IsA("BasePart") then
v.Transparency = targetTransparency
end
recursiveTransparent(v)
end
end
So you have the server-stored model transparent and then restore the transparency after.
If you have semi-transparent parts in the model then more scripting will be required.
A recursive transparency function is simple that’s not the problem here. The issue is that model gets parented by the server and the animation runs on the client. How do you propose keeping them in sync?
I have a potential fix, but first I really don’t understand how you’re not overcomplicating the issue. From what I can see the issue is that in the few frames before the model fully loads in and starts animating, it is fully visible. Why is the fix for this not just making it invisible when it loads in?
Object is already invisible/transparent
Player buys object
Object is copied/moved/parented whatever to right place
The same issue arises when do you set the transparency back to 0? Do you set it when the player presses the button to buy? If you do then the model is visible upon animation start and nothing is fixed. Do you set it after the animation ends? Then there’s desync between when the player purchases something and when the rest of the server sees what they purchased.
It would be easier to answer that if you shared what the Animation(model) function is, but as far as I can tell from the video you’ve given, the animation itself changes the transparency.
If it’s not a game you have access to, then replies like this
are worse than unhelpful. You don’t know what the issue is, but you were talking like you are.
“Plays the animation” could mean a lot of things in terms of what the actual code does
I think it’s pretty self-explanatory, no? The author even included that it is ran on the client. We can visibly see transparency & size being tweened. If you can’t use deductive reasoning don’t try to provide an answer.
Yes. You’re right. We can see transparency being tweened. Therefore we can probably assume that at the end of the animation, the transparency is at 0. Which means that we don’t need to “set it after the animation ends”. Which means that my recommended solution would work.
The only reason it wouldn’t work is if the Animate() function reset the transparency when it completed. There is no intuitive reason to do this. It would make no sense. And so using deductive reasoning, we can see that you made an non-sensical assumption and then acted like it was demonstrably true. And if you can’t make useful, honest assumptions don’t try to provide an answer.
Animations on server are incredibly bad. Very choppy, not smooth at all.
Making them load in as invisible didn’t work, as there’s no way to make them load as visible on the server then. I’d have to hook up a remote event on the client, and basically tell the server when their loading animation has happened. Problem though is exploiters can just prevent that remote event ever firing.
Ideally, I want the items to appear on the server, fully, and complete as soon as purchased. It should ONLY be the client who brought the item that sees the animations
Why don’t you just have all models already built on each slot but with Transparency=1 and CanCollide=false? This way the client has the models already loaded when you decide to do the animation.
It’s a caveman solution that actually works very well and it will be very easy to debug in the future.
My fear with it though, it tycoons being 30-40k parts each. If you have say 6 players in game at once, that’s 200k+ parts all loaded in at once, whether or not the player actually unlocks the entire tycoon or not. Seemed a lot better in the long run to just load in as purchased, as the odds of having a full server, where all players have unlocked the entire tycoon are pretty slim
Yeah that is quite smart. However, what happens when you actually do have a full server?
When your game is small this is indeed the case. But if your game ever grows, this will be a major blocker. Check any game that has over 50 concurrent players, you will notice its servers are always full. Given that the servers are always full, the probability of multiple players having full tycoons is way higher.
Anyways, if the tycoons are far enough from each other then streaming enabled will ensure it doesn’t lag. If the tycoons are close to each other, just put all the models in ReplicatedStorage until a player buys them. This way they are already in memory, but they do not get rendered (which is what causes most fps drops).