ah yeah add Value.Changed thing forgot sorry
ahh nice thank you!
asd asd I hate char limit
1
ws.DescendantAdded
since you want that for only the bricks you can add them into a folder and do
ws.BricksFOlder.ChildAdded
2
you donāt have to use pairs since instances keys are numbers
do ws:FindFirstChild("Bricks"):GetChildren()
instead of pairs(ws:FindFirstChild("Bricks"):GetChildren())
3
the script seems complicated i am guessing that you are trying to detect when a brick is collected like the Roblox incremental games if though you can do a magnitude check to check the distance
this isnāt the most efficient solution
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local bricks = workspace.Bricks -- folder to hold bricks
local character = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()
local humanoidRootPart :Part = character:WaitForChild("HumanoidRootPart")
local collectionRange = 15 -- 15 studs
RunService.Heartbeat:Connect(function()
for _, brick :Part in bricks:GetChildren() do
if (brick.Position - humanoidRootPart.Position) > collectionRange then
-- the brick is collected
brick:Destroy()
end
end
end)
now there are ways to make a more efficient version of this like using spatial hashes where the map is divided into grids its explained better in this topic in the coins collection part
Real world building and scripting optimization for Roblox - Resources / Roblox Staff - Developer Forum | Roblox
Thanks for the awesome suggestion, it isnāt quite cut out for my game yet, but Iāll adjust it
For everyone looking to get that extra 0.0001 fps: Using _ does NOT remove it from memory, all it does is just signify that you wont use it, the script will still update the _ as any other letter so it doesnāt matter what you use it only improves readability
Thanks! very useful additional information
Well, I somehow managed to fix the lag using a method similar to GE_0Eās, even if barely. Now im facing another problem (which is old):
When playing the game, the network RECV is extraordinarily high (90-300kb/s). Can anybody inform me of the does and do-nots when trying to keep the network rcv low?
Edit Note: I realised it rises when a lot of unions are replicated from the replicated storage. Is there any way to reduce this lag without removing the unions? thanks!
Edit 2: Another large problem: I beat the super-high script rate/s, but now the activity doesnt stop rising
np glad it works
high script rates is because your script is running each heartbeat/frame that isnot a problem at all
if it keeps rising without going down then make sure that you havenāt made any memory leaks
the RECV will increase whenever you replicate/send information from server to client
1- try to not send as much data through remove events
2- you can try doing optimization techniques to reduce the sent data (there are alot of topics for this)
3-any instance that gets added to replicatedStorage or workspace will increase the network recv
4-changing the properties of instances in workspace/replicated storage through server will increase the network recv
if the unions arenāt replicated often then its fine
aka replicating a map from server storage to workspace/replicated storage that will increase the Recv but only for short time
these topics map help