Automatic buttons

First

create a part and set its transparency to 1 and cancollide to false and place it above your button. Make sure to rename it to “Button1”

image

Second

local Button = workspace.Button1 -- Path to your button1

local region3 = Region3.new(Button.Position-(Button.Size/2),Button.Position+(Button.Size/2)) -- Formula for getting both the corners of the created part and then filling it with region

while wait() do
	local PartsInRegion = workspace:FindPartsInRegion3(region3,nil, 1000)
	for i,v in pairs(PartsInRegion) do
		if v.Parent:FindFirstChild("Humanoid") then
			local char = v.Parent
			local plr = game.Players:GetPlayerFromCharacter(char) -- Getting the player 

		end
	end
end
1 Like

can i olso call it multi button becose i have rebirth buttons to and stuff

Yes you can create multiple regions for detecting multiple buttons.

must be the name of the part be the same as the button name ?

No it can be different if you know what you are doing.

my first button is called 1 multi = $125 so is it the best to name the part the same

sorry for the dumb questions sometimes

1 Like

do i need to put the part in the button

You need to put the part above the button and not inside anything; you can put it inside by changing path of the variable in the above code.

it doesn’t work

can u please explain what is wrong here

can someone pls help me further

all of that is pointless really, you could achieve this, just with the Touched event, as Touched event fires whenever a certain part has been touched, it will run forever, here’s what you can do:

  • (Server) Script in ServerScriptService:
game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local valueToBeChanged = Instance.new("IntValue")
	valueToBeChanged.Name = "valueToBeChanged"
	valueToBeChanged.Parent = leaderstats
	
end)
  • (Server) Script inside the part that needs to be touched:
local debounce = true

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and debounce == true then
		debounce = false
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local valueToBeChanged = player.leaderstats:WaitForChild("valueToBeChanged")
		print("Did it!")
		valueToBeChanged.Value = valueToBeChanged.Value + 1
		wait(1)
		debounce = true
	end
end)

Ending result
Of course, it works without the second player and when CanCollide is set to either true or false on the part.

hey sorry, but how do I add these script in this script

if you already have a value and the leaderstats then just change the “valueToBeChanged” to whatever the name of your value is, and delete the first script I wrote.
an example of this would be:

  • Delete the first Server Script I wrote that was planned to be in ServerScriptService

  • (Server) Script inside the part that needs to be touched:

local debounce = true --// setting up the debounce

script.Parent.Touched:Connect(function(hit) --// fires whenever it has been touched
    if hit.Parent:FindFirstChild("Humanoid") and debounce == true then --// checking if what hit it has a Humanoid inside, and if debounce is true
       debounce = false --// setting the debounce to false
       local player = game.Players:GetPlayerFromCharacter(hit.Parent) --// finding the player
       local Money = player.leaderstats:WaitForChild("Money") --// getting the value that you wanna change
       print("Did it!") --// printing in the output just to make sure
       Money.Value = Money.Value + 1 --// how much you want to add
       wait(1) --// delay for how much it will wait until it fires the function and gives + 1 to the value again
       debounce = true --// setting the debounce back to true so the code runs again
    end
end)

you can change how much of the value it will give each time, how much it will wait until gives value again, and the value it will give, other than that, unless you know what you’re doing, don’t change anything else.

i did the script in the part that needed to be touched but it isnt going automatic if you stand still

If you use Region3, it can be as simple as

local activated = {}
local hum, player, val
while active do
    people = findPartsInRegion()
    for i, person in ipairs(people) do
        hum = person.Parent:FindFirstChildOfClass("Humanoid")
        player = hum and Players:GetPlayerFromCharacter(hum.Parent)
        if player and not activated[player] then
            val = player.leaderstats.Money
            val.Value = val.Value + 1
            activated[player] = true
        end
    end
    wait(time)
    activated = {}
end

do I plays this in the part that needs to be touched

try instead of wait(1) having wait(0.2)

i retryed the script but the script doesnt work anymore