Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a fix for this Instance.Touched problem?

Asked by 4 years ago

Let me elaborate on the background first:

I have a 32x32 layer of {1 x 0.5 x 1} bricks all next to each other in a grid. One block, in particular, is pink (more detail on that later). All of the blocks contain this script:

local brick = script.Parent
local mycolor = brick.Color
if brick.Name ~= "Part" then script:Destroy() end
local d = tick() -- works like a debounce
brick.Touched:connect(function(hit)
    if  (d+1) >= tick() or brick.Color == BrickColor.new("Medium stone grey") then return end
    hit.Color = mycolor
    d = tick()
end)

Essentially, the aforementioned pink block is theorized to "spread", and "infect" the other bricks slowly turning them pink. But it's not. I've already done some debugging and already know the problem. Apparently, the blocks' neighbors aren't triggering the function (meaning they aren't touching, even when block 1's edge is 0, 10, 0 and block 2'd edge is also 0, 10, 0). It only triggers the function if said block that is triggering the function in unanchored (meaning only unanchored blocks can trigger the touch function and not anchored ones). As of right now, all the blocks are anchored and even if you clip the blocks into each other it refuses to call the function when I can see with my 2 eyes that they are indeed touching. Is there any fix for this, and/or alternate event that's not touch?

Answer this question