Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script takes a while to detect another part, how do I make it faster?

This script is inside a part that detects other parts and see's whether or not the name of the part it's detecting is valid. If the part's name is valid then it will be unanchored and fall through the map. What I'm trying to do is make the script not have any delays when detecting the parts so it'll just check any part and unanchor it quickly. I'm not sure what to do now but if anyone has any suggestions I would really appreciate!

local childList = {}
local Min = 0
while true do
function checkObject(obj)
	if (obj ~= script.Parent) and (obj.Name == "Breakable")  then
			table.insert(childList,obj)
elseif (obj.className == "Model") or (obj == workspace) then
		local child = obj:GetChildren()
		for x = 1, #child do
			if child[x].ClassName == "Model" then
				checkObject(child[x])
			elseif child[x].Name == "Breakable" then
				table.insert(childList,Min,child[x])
			end
		end
		obj.ChildAdded:connect(checkObject)
	end
	end
checkObject(workspace)
	if Min < #childList then
	Min = Min + 1
	wait()
	else
		Min = 1
		wait()
	end
	local child = childList[Min]
	if (child ~= script.Parent) then
		local dis = (child.Position-script.Parent.Position).magnitude
		if dis <= 200 then
			child.Anchored = false
			child.CanCollide = false
			table.remove(childList,Min,child)
			Min = Min - 1
			wait()
		end
		wait()
	end
	wait()
		end

4 comments

1

Well, if you removed some of your wait()'s, it would be faster.

0

I don't know if you'll see this but, the wait()'s are needed for the script to work properly.

0

Not true, arbitrary wait calls don't properly fix anything

0

I know they don't fix everything but in this script I need either a waitforchild() somewhere in the script or a normal wait(), I'm not an amazing scripter but I know I atleast need that for the script.

1 answer

remove wait() and add game:GetService("RunService").RenderStepped:wait() try this.

2 comments

0

This is a serverscript not a localscript, sorry should've said that in the description.

0

then try game:GetService("RunService").HeartBeat:Connect(function()

This discussion is preserved as it was. New answers, comments, and votes are closed.