while true do
local soundSources = CheckZones.CheckZones()
for _, source in pairs(soundSources) do
DistanceAttenuation.GetAttenuatedVolume(source)
EarlyReflectionsRaycast.Raytrace(source)
end
wait(0.1)
for _, part in pairs(game.Workspace.SoundEngine.RaycastParts:GetChildren()) do
part:Destroy()
end
end
and this is the following it produces:
now this is the output I want. I am happy with this, however when I try to use the RenderStepped method with this code:
RunService.RenderStepped:Connect(function()
local soundSources = CheckZones.CheckZones()
for _, source in pairs(soundSources) do
DistanceAttenuation.GetAttenuatedVolume(source)
EarlyReflectionsRaycast.Raytrace(source)
end
wait(0.1)
for _, part in pairs(game.Workspace.SoundEngine.RaycastParts:GetChildren()) do
part:Destroy()
end
end)
I get this:
Now why am I complaining if the while loop method works? Well two reasons:
While loops are generally not reccomended
From the first video, you can see if the player moves the raycast initial position can’t keep up, unlike in the renderstepped on.
I dont see what the problem is? Are you talking about the lasers firing too fast? if so, the reason for it not working is since a function connected to RenderStepped doesnt wait for another function to finish before running. To fix this you could do sometihng like this using a debounce:
local Debounce = false
RunService.RenderStepped:Connect(function()
if Debounce then return end
Debounce = true
local soundSources = CheckZones.CheckZones()
for _, source in pairs(soundSources) do
DistanceAttenuation.GetAttenuatedVolume(source)
EarlyReflectionsRaycast.Raytrace(source)
end
wait(0.1)
for _, part in pairs(game.Workspace.SoundEngine.RaycastParts:GetChildren()) do
part:Destroy()
end
Debounce = false
end)
renderstepped fires every frame BEFORE roblox renders stuff, so it doesnt wait for the lazer to get destroyed before rendering another lazer (since roblox by default runs at 60fps)
RenderStepped is flying… toss a task.wait() in there. They say; While loops are generally not recommended, because if you don’t account for everything you may get stuck in an endless loop. Don’t avoid loops, account for not getting stuck in them.
You using RenderStepped for something unrelated to rendering is already scary in itself. Heartbeat (PostSimulation) is the expected default event for any work tied to RunService; the other events are for if you need fine tuning for timing because your code needs to run before physics simulation or rendering, and in the vast majority of cases, you don’t need either.