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

Why when i jump in the region3 it prints so many times?

Asked by 2 years ago
  • Where stuff is, (Make ur game R6 only)

So i have a NPC thats R6 ( its my avatar imported in r6 bascaily) and then i have RegionPart1 in workspace,for the RegionPart1 its fully transparent so u can see the region3, the regionpart is positioned in a way so it can detect u walking in it

  • The issue, So when i jump in the region3 it prints so many times compared to when i walk around in it

  • What i want fixed, I want it so it detects movement and doesnt print stuff so often

  • The script, V

---------------------
--Region

local RegionPart = game.Workspace.RegionPart1
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)
local region = Region3.new(pos1, pos2)

local part  = Instance.new("Part")
print(region.Size)

part.Anchored = false
part.Size = region.Size
part.Parent = game.Workspace
part.CanCollide = false
part.BrickColor = BrickColor.new("Really red")
part.Transparency = 0.7
part.Position = game.Workspace.RegionPart1.Position
part.Name = ("part")

local weld = Instance.new("Weld")
weld.Part0 = part
weld.Part1 = game.Workspace.RegionPart1
weld.Parent = part


--local RayCast = RaycastParams.new()
--RayCast.FilterDescendantsInstances = {
--  game.Workspace.RegionPart1,
--  game.Workspace.bily117AI
--}
--RayCast.FilterType = Enum.RaycastFilterType.Blacklist
--local RayCastResult = workspace:Raycast(part.Position, Vector3.new(25,0,0), RayCast)

--[[local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {caster.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)--]]

local IgnoreList = {
    --game.Workspace.RegionPart1,
    --game.Workspace.bily117AI,
    "Baseplate"
}

--[[while true do
    wait(1)
    local hit, position = game.Workspace:FindPartsInRegion3WithIgnoreList(region, IgnoreList, math.inf)--(region, {part, game.Workspace.bily117AI},100)--(RayCastResult, {part, game.Workspace.bily117AI})
    if hit then
        if hit.ClassName == "Part" then
            print(hit.Name)
            print("Raywas intersected another part!")
            --print(hit.Name)
            --print(hit.Name)
            --print(hit.ClassName)
            --hit:Destroy
            --hit.BrickColor = BrickColor.new("Hot pink")
        end
    else
        print("No part intercecting")
    end
end--]]

part.Touched:Connect(function(hit)
    while true do
        wait(0.1)
        --local hit, position = game.Workspace:FindPartsInRegion3WithIgnoreLis(region, game.Workspace.bily117AI:GetDescendants(), math.inf)
        local HHuman = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Humanoid
        if hit.Name == "Baseplate" then
            return false
        else
            if hit.Name == game.Workspace.bily117AI then
                return false
            else
                if hit.ClassName == "Part" then
                    print(hit.Name)
                    break
                end
            end
        end
    end
end)




















--local target = nil
--local partt = game.Workspace:WaitForChild("part")
--[[partt.Touched:Connect(function(hit)
    if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then

        print("Checkpoint 1")

        local BAIC = game.Workspace:WaitForChild("bily117AI")
        local BAICHR = BAIC:WaitForChild("HumanoidRootPart")
        local BAICH = BAIC:WaitForChild("Humanoid")
        local BAICT = BAIC:WaitForChild("Torso")
        local switch = BAIC.Switch
        switch = false
                if BAIC.Switch == true then

                end

            print("Checkpoint 2")
            wait(1)
            local target = hit.Parent       
            local goal = Vector3.new(BAICHR.Position - target.Torso.Position).magnitude
            print(goal)
            local path = game:GetService("PathfindingService"):CreatePath()
            path:ComputeAsync(BAICT.Position, Vector3.new(goal,goal,goal))
            local waypoints = path:GetWaypoints()

            if path.Status == Enum.PathStatus.Success then
                for _, waypoint in pairs(waypoints) do
                    if waypoint.Action == Enum.PathWaypointAction.Jump then
                        BAICH.Jump = true
                    end
                    BAICH:MoveTo(waypoint.Position)
                    BAICH.MoveToFinished:Wait(2)
                end
            else
                print("Path unsuccessful B")
                wait(2)
            end
        end
    end
end)--]]



discord is bily117#5405 if u need or want to dm me about it ( DMS ARE OPEN )

0
bro what the Xapelize 2658 — 2y
0
Oh my... there are over 60 lines of either code, comments, or unnecessary blank space that you did not need to include. Please try to make your questions as concise as possible.. appxritixn 2235 — 2y

1 answer

Log in to vote
0
Answered by
jundell 106
2 years ago

Don't use Region3. Use WorldRoot:GetPartsInPart, part of the new Spacial Query API. Have a loop that gets all the parts in your region part to detect players in it. If there is a player (using Players:GetPlayerFromCharacter), add them to a table. If there is no longer player (player character isn't in region part), remove them from table.

0
K ill try it when i get home bily117 6 — 2y
Ad

Answer this question