For some reason my part is growing slowly, when it should all be growing at the same time, does anyone know how to fix this? It’s supposed to grow once every second, and that’s working perfectly fine.
local function Add(numb1,numb2)
local result = numb1
for i = 1,numb2 do
numb1 = numb1 + 1
wait(0.1) --To let it think
end
script.Parent:SetAttribute("Result",numb1)
game.ReplicatedStorage.RemoteEvent:FireAllClients(script.Parent:GetAttribute("Result"),numb1,numb2)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Wait()
end
local function WaitForChild(item,name)
local child = item:FindFirstChild(name)
if child then return child end
while true do
child = item:FindFirstChild(name)
if child then return child end
item.ChildAdded:Wait()
end
end
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr,numb,result)
if numb == result then
else
while true do --Punish it so it can learn
wait()
local workspace = WaitForChild(script:FindFirstAncestorOfClass("DataModel"),"Workspace")
local newPart = Instance.new("Part",script:FindFirstAncestorOfClass("DataModel"):FindFirstChild(workspace.Name))
end
end
end)
while true do
Add(script.Parent.Size.X, 1)
script.Parent.Size = Vector3.new(script.Parent:GetAttribute("Result"),script.Parent.Size.Y,script.Parent.Size.Z)
Add(script.Parent.Size.Y, 1)
script.Parent.Size = Vector3.new(script.Parent.Size.X,script.Parent:GetAttribute("Result"),script.Parent.Size.Z)
Add(script.Parent.Size.Z, 1)
script.Parent.Size = Vector3.new(script.Parent.Size.X,script.Parent.Size.Y,script.Parent:GetAttribute("Result"))
wait(1)
end
The problem is that the for loop in the add function is yielding the while true do loop.
So you should remove the wait(0.1) from the loop, so it grows all at the same time.
Another tip is that you could use task.wait() which is more accurate.
The Roblox physics engine is kinda bad, and it dosent support a lot of instances being affected by it, this will cause lag to the server and because your script is a server script you are basically lagging the server, which makes scripts slower.
Since it seems to require precision for the part to grow, it’d be better to utilize task.wait rather than wait(n). As @af_2048 had also mentioned, you’re making it wait for a response from the client, which I’m not sure the purpose of.
This may better accomplish the resize goal.
local function IncrementSize(Part, StartSize, Increment)
local TweenTime = math.floor(Increment.X ~= 0 and Increment.X or Increment.Y ~= 0 and Increment.Y or Increment.Z ~= 0 and Increment.Z) * 0.1
TweenService:Create(Part, TweenInfo.new(TweenTime), {Size = StartSize + Increment}):Play()
end
IncrementSize(Workspace.Part, Workspace.Part.Size, Vector3.new(0, 1, 1))