New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
-1

Any way I can set a debouce?

Asked by 11 days ago

K so I have a payload region/zone, and if u see, I have print (part.Parent.Name, "Found in the Zone!") But when I go into the region/zone, I get (MyRobloxName Found in the Zone! (x14) and then it goes up and up each sec. Any way I can get it to only find the upperTorso instead of the Humanoid or if I can just set a debounce so those numbers go x1 instead of x14?

(Note: There's no problem with the script)

local payload = game.Workspace.Payload
local payloadZone = game.Workspace.PayloadZone
local inZone = game.Workspace.InnerZone
local payloadBVel = payload.BodyVelocity
local inZoneBVel = inZone.BodyVelocity

while true do
    local pos1, pos2 = (payloadZone.Position - (payloadZone.Size / 2)), (payloadZone.Position + (payloadZone.Size / 2))
    local region = Region3.new(pos1, pos2)
    wait(1)
    inZoneBVel.Velocity = Vector3.new(0,0,0)
    payloadBVel.Velocity = inZoneBVel.Velocity
    payloadZone.Position = inZone.Position
    --print ("Searching for parts to be in the Zone")
    local partsInRegion = workspace:FindPartsInRegion3(region, game.Workspace.Terrain, 100)
    local playersFound = {} --Table of players found in Region
    for i, part in pairs (partsInRegion) do
        if part.Parent:FindFirstChild("Humanoid") ~= nil then
            print (part.Parent.Name, "Found in the Zone!")
            playersFound[part.Parent.Name] = part.Parent --Add Player's Character to Table
        end
    end
    --Effect of being in the Zone
    for plrName, char in pairs (playersFound) do
        payloadBVel.Velocity = Vector3.new(-3,0,0)
        inZoneBVel.Velocity = Vector3.new(-3,0,0)       
    end
end
0
You've got an infinite while loop, of course it's going to print that you're within the zone every 1 second and there's nothing you can do about it. If you no longer check the region you wont know whether to move the payload or not. FloweryMonkeyboy5 176 — 10d
0
better to use a region3 in this case but use whatever u want lol LoganboyInCO 151 — 10d

1 answer

Log in to vote
0
Answered by 10 days ago
Edited 9 days ago

Reason your print prints 14 time is that you don't take in account if player is already in region when while true do checks. If you add another of statement to check if player is already in the list of players in region, that will solve your problem:

for i, part in pairs (partsInRegion) do
    if part.Parent:FindFirstChild("Humanoid") ~= nil then
        if not playersFound[part.Parent.Name] then —part I added
                print (part.Parent.Name, "Found in the Zone!")
                playersFound[part.Parent.Name] = part.Parent --Add Player's Character to Table
        end
    end
end
0
Where do I put the "and" Dudez2Good4u 8 — 10d
0
I said “and” statement, but I wrote not in the code. I meant if you added not like I did at line 3, to check if player is already in list of players in region. I will edit my answer GooierApollo664 163 — 9d
Ad

Answer this question