How can i make this barrier for mining work

So, blocks should exist only on one corner, and not another?
If yes, then:

local X = (OreCF.X-Origin.X)/6
local Z = (OreCF.Z-Origin.Z)/6
if (X >= 8 and X < 0) or (Z >= 8 and Z < 0) then return end

Now the area doesnt have any barriers

oof, sorry. I made small mistake with <> symbols

if (X <= 8 and X > 0) or (Z <= 8 and Z > 0) then return end

This is what happened:
image

hm, IDK why this occured. Did you kept this?

local X = (OreCF.X-Origin.X)/6
local Z = (OreCF.Z-Origin.Z)/6

Yes i need to keep that or it will error

IS your ORIGIN at 0, 0 now? Because the only reason it can behave like this is incorrect origin or incorrect subtraction. Maybe, try switch spots for OreCF and Origin (Origin - OreCF)

The origin is at 0,0,0 and i only have it so that i can tell the right amount of blocks

Then IDK what causes this issue, try manipulate with some variables by random? Sorry.

I saw other mining games have barriers too so there must be something to solve this issue

Yes, thereā€™s should be answer. But itā€™s hard to do smth if you donā€™t know everything.
At what I see rn, you have code which:

  1. Has Ore position and Origin position. (0, 0)
  2. Letā€™s take some ore positions like a = (5, 3), b = (1, 1), c = (10, 4), d = (-4, 0), assuming that they are divided by 6 already.
  3. Substracting from ore positions origin position (remember that I divided by 6 already): ra = (5 - 0, 3 - 0) = (5, 3) and etc.
  4. Then compare them to borders, if X inside (0, 8) and Z inside (0, 8), then allow block to spawn:
    a.X <= 8 -> yes . . . a.X > 0 -> yes . . . a.Z <= 8 -> yes . . . a.Z > 0 -> yes ā†’ allow spawn
    b.X <= 8 -> yes . . . b.X > 0 -> yes . . . b.Z <= 8 -> yes . . . b.Z > 0 -> yes ā†’ allow spawn
    c.X <= 8 -> NOU . . . c.X > 0 -> yes . . . c.Z <= c -> yes . . . c.Z > 0 -> yes ā†’ disallow spawn
    d.X <= 8 -> yes . . . d.X > 0 -> NOU . . . d.Z <= 8 -> yes . . . d.Z > 0 -> NOU ā†’ disallow spawn
  5. You should see a and b block placed, while c and d wonā€™t.

Thatā€™s how I see it working.

1 Like

I also would see it working like that but how do i turn it into a if statement

UNDERSTOOD (I think)

if (X <= 8 and X > 0) and (Z <= 8 and Z > 0) then
--CODE TO SPAWN BLOCK!!!
end

(I did code to spawn block, but not to prevent it from spawning .-.)
So if you want use return end, then use

if not ((X <= 8 and X > 0) and (Z <= 8 and Z > 0)) then return end=
1 Like

That doesnt spawn any blocks at all

Try that codes again, I changed <> symbols again =|

1 Like

Doesnā€™t work sorry i think ill rewrite my system or something

Maybe, Iā€™ll be able to fix it. But I need see entire code and run/debug it. Can you give me file with place? (If you want)

1 Like

Are there negative coordinates involved here? (e.g. Z = -10, X = number) That could be the problem, because math.abs CANNOT return a negative number (it returns the absolute, non-negative value). It would instead return the positive equivalent (ex: math.abs(-6) = 6). For example, if OreCF.X is -10 and Origin.X is 10, then math.abs((OreCF.X-Origin.X)/6) will return 3.33, which is less than 24, even though the distance is actually 20. Instead, try using

-- Change this variable, this is the distance limit.
local max = 24

local X = (OreCF.X-Origin.X) -- Difference between X
local Z = (OreCF.Z - Origin.Z) -- Difference between Z coords
local distance = math.sqrt(X^2 + Z^2) -- Square root of XĀ² + ZĀ²
if distance >= max then return end -- If the distance is greater than the max variable, skip the block placing.

I obviously havenā€™t tested this, but it could work. This would create a circular barrier as it uses Euclidean distance, but I think itā€™s better than nothing. Also, the max variable I provided would probably too large, make sure to change it.

1 Like

That still doesnt work for me because in one corner i can mine 24 blocks sideways and in the other i can mine only 1.

Could you give me a screenshot of that?

1 Like