-
What do you want to achieve?
Some sort of sonar system that doesnt do what its currently doing -
What is the issue?
From the attached video you can see that after a while, more specifically when MaxDotGroups is reached all the dots on the walls delete themselves for some reason, after this happens the walls are no longer detected and the balls on the floor multiply for some reason, I’m unsure if the walls are the issue or that only the floor dots arent being deleted. -
What solutions have you tried so far?
I’ve went and visualized the rays being shot, enable framedebugvisibility to see a grid of squares on the screen that indicate where the ray is aiming, I’ve also made sure the rays are still hitting the walls via ray.Instance and they are indeed hitting the walls.
local reps = 100 --amount of subdivisions and rays being shot, 10k times out dont do that lol
local showntime = (5/2) --wip
local raymaxreach = 1000 --max length the rays will go
local maxSpecialDot = 30 --limit of nonNormal dots
local SpecialDotOverflowProt = 2 --dividing total number of a groups dots to delete
local maxDotGroups = 5 --normal dot group limit, groups are as big as the rep value
local dotOverflowProt = 1--(maxDotGroups/2)
local rows = math.floor(math.sqrt(reps))
local counter = 0
local oringin = UDim2.fromScale(0,0)
local endpoint = UDim2.fromScale(1,1)
local pos = UDim2.fromScale(0,0)
local offsetx = UDim2.fromScale(1/rows,0)
local offsety = UDim2.fromScale(0,1/rows)
local framedebugvisibility = false
local groups = {
["Normal"] = {
["ParentName"] = "nonSpecialSurroundings",
["Colour"] = Color3.fromRGB(255,255,255),
["Name"] = "Normal",
["Objects"] = {}
},
["Enemy"] = {
["ParentName"] = "dangerousSurroundings",
["Colour"] = Color3.fromRGB(255, 0, 0),
["Name"] = "Enemy",
["Objects"] = {}
},
["KeyItem"] = {
["ParentName"] = "specialSurroundings",
["Colour"] = Color3.fromRGB(56, 255, 25),
["Name"] = "KeyItem",
["Objects"] = {}
},
}
for i, group in groups do
if group.Name ~= "Normal" then
local enemyhlmodel = Instance.new("Model")
local diffhl = Instance.new("Highlight")
diffhl.FillColor = group.Colour
diffhl.Parent = enemyhlmodel
diffhl.DepthMode = Enum.HighlightDepthMode.Occluded
enemyhlmodel.Parent = workspace
enemyhlmodel.Name = group.Name
table.insert(group.Objects, enemyhlmodel)
print(group, group.Name, enemyhlmodel)
end
end
local lastime = tick()
local rcp = RaycastParams.new()
rcp.FilterDescendantsInstances = {game:GetService('Players').LocalPlayer.Character, groups.Normal.Objects, groups.KeyItem.Objects, groups.Enemy.Objects}
game:GetService("UserInputService").InputBegan:Connect(function(key, gpe)
if not gpe and key.KeyCode == Enum.KeyCode.E then
lastime = tick()
for iteration = 0, reps do
if iteration % rows == 0 then
counter = counter + 1
-- print("Counter: " .. counter)
pos = UDim2.new(oringin.X, pos.Y)
pos += offsety
end
--print(iteration)
if iteration == reps then
local a = script.Frame:Clone()
a.Visible = framedebugvisibility
a.Name = iteration
a.Parent = script.Parent
a.Position = endpoint
task.wait(0.1)
local model = Instance.new("Model")
table.insert(groups.Normal.Objects, model)
model.Parent = workspace
for i, frame in script.Parent:GetChildren() do
if frame:IsA("Frame") then
local rayinf = workspace.CurrentCamera:ViewportPointToRay(frame.AbsolutePosition.X, frame.AbsolutePosition.Y, 0)
rcp.FilterDescendantsInstances = {game:GetService('Players').LocalPlayer.Character, groups.Normal.Objects, groups.KeyItem.Objects, groups.Enemy.Objects}
local ray = workspace:Raycast(rayinf.Origin, rayinf.Direction * raymaxreach , rcp)
if ray then
--print(ray.Instance)
local part = Instance.new("Part")
part.Shape = Enum.PartType.Ball
part.Parent = workspace
part.Anchored = true
part.Size = Vector3.new(1,1,1)
part.Material = Enum.Material.Neon
part.Position = ray.Position
part.Transparency = 0
part.CanCollide = false
part.LocalTransparencyModifier = 0
if ray.Instance.Parent.Parent:GetAttribute("Enemy") or ray.Instance.Parent:GetAttribute("Enemy") or ray.Instance:GetAttribute("Enemy") then
part.Parent = groups.Enemy.Objects[1]
end
if ray.Instance.Parent.Parent:GetAttribute("Normal") or ray.Instance.Parent:GetAttribute("Normal") or ray.Instance:GetAttribute("Normal") then
part.Parent = groups.Normal.Objects[2]
end
if ray.Instance.Parent.Parent:GetAttribute("KeyItem") or ray.Instance.Parent:GetAttribute("KeyItem") or ray.Instance:GetAttribute("KeyItem")then
part.Parent = groups.KeyItem.Objects[1]
end
end
rcp.FilterDescendantsInstances = {game:GetService('Players').LocalPlayer.Character, groups.Normal.Objects, groups.KeyItem.Objects, groups.Enemy.Objects}
frame:Destroy()
end
end
pos = oringin
if not model:FindFirstChildOfClass("Beam") then
if table.find(groups.Normal.Objects, model) then
local beam = Instance.new("Highlight")
beam.FillColor = Color3.fromRGB(255, 255, 255)
beam.DepthMode = Enum.HighlightDepthMode.Occluded
beam.Parent = model
elseif table.find(groups.Enemy.Objects, model) then
print("B")
local beam = Instance.new("Highlight")
beam.FillColor = Color3.fromRGB(255, 0, 0)
beam.DepthMode = Enum.HighlightDepthMode.Occluded
beam.Parent = model
elseif table.find(groups.KeyItem.Objects, model) then
local beam = Instance.new("Highlight")
beam.FillColor = Color3.fromRGB(60, 255, 0)
beam.DepthMode = Enum.HighlightDepthMode.Occluded
beam.Parent = model
end
end
--[[for i, thing in models do
print(thing)
end]]
for i, group in groups do
if group.Name == "Normal" then
if #group.Objects >= maxDotGroups then
local rng = math.random(1, #group.Objects)
if not group.Objects[rng]:IsA("Highlight") then
group.Objects[rng]:Destroy()
table.remove(group.Objects, rng)
end
end
else
--print(group)
-- print(#group.Objects[1]:GetChildren() >= maxSpecialDot, #group.Objects[1]:GetChildren())
if #group.Objects[1]:GetChildren() >= maxSpecialDot then
local db = false
for count = 0, #group.Objects[1]:GetChildren()/SpecialDotOverflowProt, 1 do
print(count)
db = false
for i, obj in group.Objects[1]:GetChildren() do
if obj:IsA("Part") and db == false then
obj:Destroy()
db = true
end
end
end
end
end
end
return
end
local a = script.Frame:Clone()
a.Visible = framedebugvisibility
a.Name = iteration
a.Parent = script.Parent
if iteration == 1 then
a.Position = pos
end
pos += offsetx
a.Position = pos
end
end
end)
--[[game:GetService("RunService").Heartbeat:Connect(function()
for i, group in groups do
if group.Name ~= "Normal" then
if group.Objects[1]:IsA("Model") and not (((tick() - lastime) - showntime) <= showntime) then
for i, ball in group.Objects[1]:GetChildren() do
ball:Destroy()
end
end
else
if group.Objects[1]:IsA("Model") and not (((tick() - lastime) - showntime) <= showntime) then
group.Objects[1]:Destroy()
end
end
end
end)
]]
here is the hierarchy of everything, things I want the dots to stick to have 1 of 3 attributes, either Normal, Enemy or KeyItem.
Studio download;
sonarbutdumb.rbxl (81.4 KB)