Help on fixing "Touched/TouchEnded" script

how would I use it, I have no idea to.

I recommend reading through this to get a bit more familiar with raycasting. If that still doesn’t help I could maybe show an example of what I mean

1 Like

Since the area is a cylinder, you can check the distance between the center of the area and the player, and check if the distance is inferior or equal to the radius of the cylinder.

game.RunService.Heartbeat:Connect(function(step)
    for _, player in ipairs(game.Players:GetPlayers()) do
        local distance = player:DistanceFromCharacter(zone.Position)
        if distance ~= 0 and distance <= zone.Size.X/2 then
            -- player in zone
        else
            -- player not in zone
        end 
    end
end)

hmm works when its resizing too??

Yes, since it will check the distance based on the radius of the zone.

1 Like

im not keen in lua mathing but ill try it out tmr! Please tutor me if I need.

I mean how to get the thickness as it changes as I resize it, literally I cant find the math for it

well the fact is, the zone’s Cframe is higher than player’s CFrame so cant do that. I’m thinking of raycast but idk how to get the thickness of the zone’s borders

Then either move the zone down and make it taller or check a modified CFrame

game.RunService.Heartbeat:Connect(function(step)
    for _, player in ipairs(game.Players:GetPlayers()) do
        local distance = player:DistanceFromCharacter(Vector3.new(zone.Position.X, player.Character.PrimaryPart.Position.Y, zone.Position.Z))
        if distance ~= 0 and distance <= zone.Size.X/2 then
            -- player in zone
        else
            -- player not in zone
        end 
    end
end)

Then there would be a huge gap under the map which may cost major lag.

Touch and TouchEnded don’t really work properly as it only detects player movement when you enter.

(As well it renders touch ended too early or too late, Or just never detects.)

I suggest using Region3’s to make your thing work, Or you could use Zone+ (A helpful thing which would make working with region3 easier. https://devforum.roblox.com/t/zone-retrieving-players-within-an-area-zone/397465

1 Like

Thanks for replying lately. But it seems like I’ve handled it with magnitude by comparing the X-axis only.