AFK Zone where to earn money every x amount of time

I want to have an area where you can earn money every x seconds without having to move.
I can only find scripts where you have to move.
For example this one:

local ting = 0 --debouncer
function onTouched(hit)
if ting == 0 then --debounce check
ting = 1 --activate debounce
check = hit.Parent:FindFirstChild(“Humanoid”) --Find the human that touched the button
if check ~= nil then --If a human is found, then
local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human
local stats = user:findFirstChild(“leaderstats”) --Find moneyholder
if stats ~= nil then --If moneyholder exists then
local cash = stats:findFirstChild(“Bloins”) --Get money
cash.Value = cash.Value +4 --increase amount of money by the number displayed here (500)
wait(20) --wait-time before button works again
end
end
ting = 0 --remove debounce
end
end
script.Parent.Touched:connect(onTouched)

What should I modify to get it?
Thanks

1 Like

I think the logical solution to this would be Region3. The post below is an example of how you can use it.

You can also use Zone+ created by @ForeverHD. The post below includes the answers to any questions you might have about the module and several examples of how to use it.

2 Likes

Thanks, but if it is not too much to ask do you know what exactly I should modify?
I have been looking at the two options you gave me, but I can’t figure it all out.

Sorry for the late response I wasn’t home. If you can’t figure it out I think it’s best to go with Zone+ as it is the easiest to use. First of all, you should require the module

local ZonePlus = require(script.Zone) --//The text in the bracket should be the path to your module.

After that, you should continue with creating your zone. You can set a placeholder part for the module to use when creating the zone.

local Container = workspace.ContainerPart --//This should be the path to your placeholder part.
local Zone = ZonePlus.new(Container) --//This creates the zone

Now we should get the players entering and leaving the zone, and we should store the information we have in a dictionary. There might be other more efficient ways to do this but this is what I prefer at the moment.

local Players = {}

zone.playerEntered:Connect(function(player)
    Players[player] = true
end)

zone.playerExited:Connect(function(player)
    Players[player] = nil
end)

Now that we have all the players within the zone, we can go ahead and create a loop that gives them money.

while wait(20) do --//The number in the brackets should be the time the player has to wait for coins
 for player,_ in next, Players do
    local Stats = player:FindForChild("Stats")
    if Stats ~= nil then
          local Cash = Stats:FindFirstChild("Bloins")
          Cash.Value += 4
     end 
 end
end

I don’t understand what you are saying, I have a block where when you enter I have a script that gives you money every x time, but you need to move, because otherwise it doesn’t give it to you.
So I don’t want you to need to move.
I can’t understand your scripts, isn’t it enough just to have a script in the block?
Here I attach images for a better understanding:
Captura de pantalla 2022-05-09 220123
Captura de pantalla 2022-05-09 220816

Some Region3 functions are deprecated. These include for example FindPartsInRegion3().
I would suggest learning + using Introducing OverlapParams - New Spatial Query API

I think you can made a code that when you touch the afk zone if the player is idle then earn money all x times ! :grinning: