Checking character touches object

I’ve been working on some kind of scrip that leaves behind a kind of path when the player walks (this happens in a serverscript). I start with the playeradded function to get the character, and then the humanoid (just incase i need that), together with the HumanoidRootPart. I constantly check the players position and do some maths on that position to get the position i really need; divide by 3 then .Ceil then multiply by 3 (so it acts like a grid). Now i’m able to place a part where the player stood.

Now here’s the problem: I don’t need a part to appear where there already is a part, else the game crashes due to too many spawning in… I don’t know how to check if there’s a part where the game is trying to place a part. Can somebody help me out? (i was thinking of using players position, but that would be hard. I was also thinking of using .Touched or even .TouchEnded… but you tell me)

1 Like

You can create a Region3 with the part’s Bounding Box, then use workspace:FindPartsInRegion3() to find the parts that are overlapping that region3.

Check to see if the player is running or not, that way you can minimise the amount of spawns in one position, doing:

    humanoid.Running:Connect(function(speed)
    if speed > 0 then
    —Code here
    else
    — Other thing
end
end)

(Written on mobile, so format isn’t great)

Region3 only works reliably if the parts are not rotated (or at 90° steps) and of shape block (since these restrictions apply to Region3s respectively).

That doesn’t seem like a problem if you don’t need the part to be rotated or have a shape, and just need to place it in the player position.

Absolutely, but it’s a tight restriction and OP didn’t mention anything about part rotation / shape. Just a heads up.

It’s a flat snow part, it’s not rotated and it’s a square.

1 Like

If so, FindPartsInRegion3 is probably a better solution since it doesn’t require spawning in parts and I’m positive it’s more performant too.
You can calculate the bounds for a given part like so:
Region3.new(part.Position + part.Size / 2, part.Position - part.Size / 2)

Since the position describes the center, half of the size is exactly the distance you need to travel to reach a corner.

1 Like