I’m making a script which tweens the scale of a model by changing the value of a function with :ScaleTo in it, but the issue is that the scale is only updating once every two frames, making it visibly choppy as it changes size. Is there a solution to this?
Can something like this work?
local function ScaleTweenModel(Model: Model, Scale: number)
local v = Instance.new("NumberValue")
v.Value = Model:GetScale()
local tw = game.TweenService:Create(v, TweenInfo.new(0.5), {Value = Scale})
local thr = nil
thr = game:GetService("RunService").RenderStepped:Connect(function()
Model:ScaleTo(v.Value)
end)
tw.Completed:Once(function()
thr:Disconnect()
v:Destroy()
end)
end
Hello, this script is essentially what I made which unfortunately ended up being choppy. My script is a server script so I cannot use renderstepped.
What about Heartbeat? That’s usually 60fps.
If it’s still choppy then use remotevents and scale on the client. Scaling on the server may always be choppy.
I tried this and it appears that it didn’t work. If it’d help you, I can send the server and local script I currently have.
Are you already scaling in a local script or on the server? I would like to see the Server code and the Client coede.
I think Stepped is mostly the same thing but runs before physics or something like that, but I suppose OP could give it a try
Here’s the server script:
game.ReplicatedStorage.InputEvent.OnServerEvent:Connect(function(player,mousehit)
local blackhole = game.ReplicatedStorage.BlackHole:Clone()
local scale = Instance.new("NumberValue")
task.spawn(function() --Makes boundary visible after spawning
while blackhole.Field.Transparency > .75 do
task.wait()
blackhole.Field.Transparency -= .04
end
end)
scale.Value = .75
blackhole:PivotTo(mousehit)
blackhole.Field.Sound:Play()
blackhole.Parent = game.Workspace
task.spawn(function() --Disables particles and destroys after lifetime is over
task.wait(8)
local particles = blackhole:GetDescendants()
for i, v in pairs(particles) do
if v:IsA("ParticleEmitter") then
v.Enabled = false
end
end
task.wait(2)
blackhole:Destroy()
end)
local ts = game:GetService("TweenService")
local tween = ts:Create(scale,TweenInfo.new(8.5,Enum.EasingStyle.Linear),{Value = 3})
tween:Play()
game:GetService("RunService").Heartbeat:Connect(function()
game.ReplicatedStorage.ScaleEvent:FireAllClients(scale.Value,blackhole)
end)
task.spawn(function() --Makes boundary fade after lifetime
task.wait(8)
while true do
task.wait()
blackhole.Field.Transparency += .02
end
end)
end)
And here’s the client script:
game.ReplicatedStorage.ScaleEvent.OnClientEvent:Connect(function(scale,blackhole)
blackhole:ScaleTo(scale)
end)
The remote event that the server script is receiving from is just a basic input detector.
You should do the full process on the client (I mean the visual processes you should find a way)
Do not try to do visual effects on the server. It will always come out looking choppy, you should attempt to render effects like smooth scaling on individual clients so it uses the players’ hardware to compute the size changes. Simply use a remote event that sends it to all clients, passing the model and scale arguments.
Exactly. Have the server send an event to the client to start the scale animation, and have the client actually do the work. Then, on the client, you can use RenderStepped and DeltaTime to make the animation smooth and play at the same speed for all clients.
Something like this:
game.ReplicatedStorage.InputEvent.OnServerEvent:Connect(function(player,mousehit)
local blackhole = game.ReplicatedStorage.BlackHole:Clone()
blackhole:PivotTo(mousehit)
blackhole.Field.Sound:Play()
blackhole.Parent = workspace
task.spawn(function() --Disables particles and destroys after lifetime is over
task.wait(8)
local particles = blackhole:GetDescendants()
for i, v in pairs(particles) do
if v:IsA("ParticleEmitter") then
v.Enabled = false
end
end
task.wait(2)
blackhole:Destroy()
end)
game.ReplicatedStorage.ScaleEvent:FireAllClients(blackhole)
end)
client:
local TweenService = game:GetService("TweenService")
game.ReplicatedStorage.ScaleEvent.OnClientEvent:Connect(function(scale,blackhole)
local info = TweenInfo.new(8.5, Enum.EasingStyle.Linear) -- set your scale value
local tween = TweenService:Create(blackhole, info, {Scale = 3})
tween:Play()
task.wait(8)
for i = 0, 1, .02 do -- for variable, target, increment
task.wait()
blackhole.Field.Transparency += .02
end
end)
Note: I didn’t test this code so it probably doesn’t work
, but hopefully you get the main point.
Choppiness happens because ScaleTo only updates when the engine refreshes the model’s scale, which doesn’t occur every frame. You can’t force ScaleTo to update each frame. Depending on the model, there are workarounds, but ScaleTo isn’t one of them. To achieve smooth scaling, use the Size property with a simple tween. You can do that all from the server flawlessly.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.