Hello, I have been wondering how I could possibly detect if a function inside a SERVER SCRIPT has started running WITHOUT VARIABLES.
I have been looking around but all I found was a solution with variables (which is not what I want to use, because then I need to use LOOPS) or questions about module scripts.
example:
local function HandleButtonPress()
--something
end
spawn(function()
--something
--detect when the HandleButtonPress function is run and run its own code
end)
--code
HandleButtonPress()
--/code
Just run a function when HandleButtonPress() runs.
local function OnButtonPressFunction()
--Code
end
local function HandleButtonPress()
--something
task.spawn(function()
OnButtonPressFunction()
end)
end
HandleButtonPress()
That would unecessarily overcomplicate things. look closely at my code example, it has alot to do with my current code just without the unecessary details.
I want code inside of the spawn function (see example code) to check if the function HandleButtonPress was ran without any help of the outside parts (basically an independent piece of code)
I need multiple of those variables at a time because the function looks for instances by the name of “_Button”…buttonnum
it will then create a bindable event corresponding to it inside of a folder, so putting all of these variables outside of the spawn function will just extremely overcomplicate things
I don’t know what kinda weird code you have but just use another bindablevent and fire it when the function is called
just know there are way more clean ways to achieve what you want but you didn’t show any other code
that other code is kind of irrelevant but i guess ill show you
local buttonNum = 1
local maxBtnCount = 15
local sound = workspace.SFX.ButtonPress
local buttn = "_Button"
local debounce = false
local bdeb = false
local interactive = {}
local specials = require(script.SpecialActions)
local function MaxButtons()
if buttonNum > maxBtnCount then
print("die")
local humanoid = game.Players:GetPlayers().Character.Humanoid
humanoid.Health = 0
end
end
local maps = game.ServerStorage.Maps
local function HandleButtonPress(button)
if debounce == false then
--irrelevant code
else
return
end
end
spawn(function()
--relevant code
local nown = 1
repeat
local bas = workspace:FindFirstChild("_Button"..nown, true)
if bas then
local ev = Instance.new("BindableEvent", script.Parent.Bindables)
ev.Name = tostring("Bindable"..nown)
nown+=1
--HandleButtonPress() = function()
--end
else
nown = -1
end
until
nown == -1
end)
for i = 1, maxBtnCount do
local button = workspace:FindFirstChild(buttn..i, true)
if button then
button.Hitbox.Touched:Connect(function(hit)
if not bdeb then
bdeb = true
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
script.Parent.Button:Fire(p, i)
HandleButtonPress(button)
button.Hitbox.CanTouch = false
end
end
end)
end
end
I might have not gotten something since this code is horrendous but can’t you just connect to the bindableevent since you are firing it with the function?
readability + cleanliness + for loops are easier to write
also you are searching through the ENTIRE workspace every time you are searching for a button (workspace:FindFirstChild(“_Button”…nown, true)) put them in a model or a folder
(rewrite this pls)