I made an object with a surface GUI and some data gathered thanks to Region3 (works and its efficient code)
The bug is that when i spawn an object over the "data area" i get a number from that object. Ok that works, it's fine.
Now, if i spawn new objects that gather data, even though this "data" its outside the area, the newly spawned objects have the same value in the surface GUI.
In short words, the data gathered by the first, will be the data showed in the surface screen for all the newly spawned objects.
Edit: The main code named Drill (outside the SurfaceGUI but important).
local work = game.workspace
Deposit = work.Part.Deposit
local event = Instance.new("BindableEvent")
event.Parent = game.workspace.Events
event.Name = "Action"
local list = {work.Baseplate, work.Part}
local function CreateRegion3FromLocAndSize(Position, Size)
local SizeOffset = Size/2
local Point1 = Position - SizeOffset
local Point2 = Position + SizeOffset
Region = Region3.new(Point1, Point2)
return Region
end
local start_pos = work.Part.Position
local Size = Vector3.new(5, 2, 5)
CreateRegion3FromLocAndSize(start_pos, Size)
Region = Region:ExpandToGrid(4)
--work.Terrain:FillRegion(Region, 4, Enum.Material.Slate)
local parts = work:FindPartsInRegion3WithIgnoreList(Region, list, 10)
for i = 1, #parts do
print(parts[i].Name, " <- Part Name")
print(parts[i].Oil.Value, " <- Value of Reserve")
function Pumpy(action)
if action == true then
print("Pump Activated!")
else print("Pump Stopped!")
end
end
event.Event:Connect(Pumpy)
Deposit.Value = parts[i].Oil.Value
--print("Deposit ", Deposit.Value)
end
And then the code inside the SurfaceGUI to display that "Deposit Amount"
local load = workspace:WaitForChild("Part")
print("Reserves Button Initialized")
local Reserve = game.Workspace.Part.Deposit
local script = script.Parent
script.Text = (Reserve.Value)
--print("Reserve", Reserve.Value)
Both are server scripts. Not Local. Feel free to use any idea of this code or try to improve it. I do not care about credits but learning. Thanks
The bug is that that data taken from the first Oil Reserve will be displayed to every newly spawned object aka Drill

4 comments
All those "objects" are the same model. The data area in a part with some data in. The Region3 helps me gather it
Are you saying that each thing you put in the "data area" has a number associated with it that the surface GUI is to display? I think we need to see the code that isn't working as you expect to help you.
Never store remote/bindable events in the workspace. Thats how your game can get hacked. All it takes is a hacker to do game.Workspace.Events.Event:Fire()
For now im just working on concepts but thanks for the advice