-
What do you want to achieve?
Make the rays updating accordingly and prevent studio from crashing -
What is the issue?
Studio
https://gyazo.com/3042b42e2e496d6894f58f4c31c95023 ← X.1 size avg size I wish to use it like this
https://gyazo.com/e322d7755cfe422cad88eb447489153a ← X25 size, appears it doesn’t crash at this size -
What solutions have you tried so far?
I have made the sphere bigger which slowed down the script and worked but making it smaller and attempting to slow it down with waits resulted it to crash, removing the code to update the ray table while its small also prevents it from crashing
This script creates a sphere with the num points, also highlights some of them
https://gyazo.com/6e302f4c0a176c1ae95a28a03efc43a8 ← example of sphere at X25 size
After the sphere is created it loops over each part and shoots out a ray (360 rays/1 per part)
https://gyazo.com/e322d7755cfe422cad88eb447489153a ← sphere at X25 size but now shooting rays
I don’t know what else to write here if you don’t understand parts of my poorly written script just ask
local numPoints = 360 -- number of points on the sphere
local turnFraction = 0.61803 -- golden ratio
local defaultcolor = BrickColor.new("Royal purple") -- default cphere clr
local highlight = 2
local highlightoffset = 0
local sspawn = game.Workspace.CircleSpawn
local PS = sspawn.Position -- point where to spawn
sspawn:Destroy()
local colsraysize = 25
local function VisualizeRay(part, pos, clr, mod, name) -- visualize ray, part/pos = used for cframe, clr = used for changing color, mod = modifier for the ray size, name = rays name
local RayVisualize = Instance.new("Part")
RayVisualize.CanCollide = false
RayVisualize.Anchored = true
RayVisualize.Name = name
RayVisualize.Size = Vector3.new(.25, .25, colsraysize + mod)
RayVisualize.Color = clr
RayVisualize.CFrame = CFrame.new(part.CFrame.p, pos) * CFrame.new(0, 0, -(colsraysize + mod) / 2)
RayVisualize.Parent = game.Workspace.BirdRays
end
local function PlotPoint(x, y, z, clr) -- create a ball at X/Y/Z then look at center
local new = Instance.new("Part")
new.Shape = "Ball"
new.Parent = game.Workspace.circle
new.Anchored = true
new.Size = Vector3.new(6.5, 6.5, 6.5)
new.Position = PS + Vector3.new(x, y, z)
new.CFrame = CFrame.new(new.Position, Vector3.new(PS.X, PS.Y, PS.Z))
new.BrickColor = clr
return new
end
local function IgnoreList()
local il = {}
for i,v in pairs(game.Workspace.BirdRays:GetChildren()) do
table.insert(il, v)
end
for i,v in pairs(game.Workspace.circle:GetChildren()) do
table.insert(il, v)
end
return il
end
for i=0, numPoints, 1 do -- this creates the actually sphere https://stackoverflow.com/questions/9600801/evenly-distributing-n-points-on-a-sphere/44164075#44164075
spawn(function()
local t = i / (numPoints-1)
local inclination = math.acos(1 - 2 * t)
local azimuth = 2 * math.pi * turnFraction * i
local angle = 2 * (math.pi * (turnFraction * i))
local x = math.sin(inclination) * math.cos(azimuth) * .1
local y = math.sin(inclination) * math.sin(azimuth) * .1
local z = math.cos(inclination) * .1
local color = defaultcolor
if ((i+highlightoffset) % highlight == 0) then
color = BrickColor.new("Gold")
end
local thing = PlotPoint(x, y, z, color)
end)
end
wait(.01) -- make sure sphere is made
spawn(function()
while true do
game.Workspace.BirdRays:ClearAllChildren() -- remove all rays
for i,v in pairs(game.Workspace.circle:GetChildren()) do
spawn(function()
local il = IgnoreList()
local newray = Ray.new(v.Position, -v.CFrame.lookVector*(colsraysize)) -- invert direction of ray so its firing away from the sphere
local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(newray, il)
if hit and i <= 270 then -- the 270 is for a future script that will be using this
VisualizeRay(v, pos, Color3.fromRGB(0, 255, 0), 0, i) -- green if hit
elseif hit and i > 270 then
VisualizeRay(v, pos, Color3.fromRGB(0, 0, 0), 0, i) -- black if hit but out of FOV
elseif i <= 270 then
VisualizeRay(v, pos, Color3.fromRGB(0, 0, 255), 0, i) -- blue if in FOV
else
VisualizeRay(v, pos, Color3.fromRGB(255, 0, 0), 0, i) -- red if out of FOV
end
end)
end
wait()
end
end)
If you know how i can improve this please reply