Hello developers, I am currently working on a slot system and I couldn’t really find any efficient solutions to achieve my goal.
So, I am trying to create a system that whenever a new slot gets bought, the slots near it gets purchasable too. I have thought about making a database to store every slots and the slots near them, but this is not efficient enough for me. I am looking for a real solution for this.
Here is my workspace and how the slots are stored:
local Parts = game.Workspace:WaitForChild("Parts")
local Pink = Color3.fromRGB(253, 20, 242)
local Grey = Color3.fromRGB(163, 162, 165)
for _, item in pairs (Parts:GetChildren()) do
local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = item
ClickDetector.MouseClick:Connect(function()
for _, other in pairs(Parts:GetChildren()) do
other.Color = Grey -- reset all
if (item.Position - other.Position).Magnitude <= 12 then other.Color = Pink end -- change to pink
end
item.Color = Grey -- reset item
end)
end
Another way which can reduce load, assuming the size of the slots are all a static size is:
From the midpoint of the bought slot, fire a raycast offsetted to each potential slot near it (easily calculated since they are squares). If a raycast hits, a slot is there, and then do whatever logic you need (you’ll have the raycastresult data to work with)
Create a script that gives the slots an attribute of x and z and, for example, if you buy slot x=4, z=3, you can calculate which slots become visible in this case slot x=3, z=3 and x=5 ,z=3 etc.