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”
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
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.
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.
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