i want a function (part.touched:…) to be executed once, when i want.
I want to make a loop wait until the function executes.
my code simplified
local table1 = {"A","B","C"}
function()
local triggerfunction = false
for i,v in pairs(table1) do
if v == "A" then
triggerfunction = true
-- i want to wait with this loop until "Part" touches something
end
end
end
if tiggerfunction then
-- i want this function to only trigger once
part.touched:Connect(function() end)
end
function()
local triggerfunction = false
for i,v in pairs(table1) do
if v == "A" then
triggerfunction = true
-- i want to wait with this loop until "Part" touches something. Also how to do this?
end
end
end
You could just do something like this, since I still don’t understand what you mean.
local touchedConnection
local function Disconnect()
if touchedConnection then
touchedConnection:Disconnect()
touchedConneetion = nil
end
end
local function Connect()
touchedConnection = part.Touched:Connect(function()
Disconnect()
end
end
Connect() -- Whenever you want to connect the function you would use Connect()
local triggered = false
part.Touched:Connect(function()
triggered = true
end
local Table = {"A", "B", "C"}
for _, String in ipairs(Table) do
if not triggered then repeat task.wait() until triggered end
-- Do whatever you want here
end
oh wait. i realized i wrote my “example codewrong”
its suppost to be
local table1 = {"A","B","C"}
function()
local triggerfunction = false
for i,v in pairs(table1) do
if v == "A" then
triggerfunction = true
-- i want to wait with this loop until "Part" touches something
end
end
if tiggerfunction then
-- i want this function to only trigger once
part.touched:Connect(function() end)
end
end
it doesn’t work in here. should i place it inside the loop?
local var: number = 5
var = "string" -- Type `string` could not be converted into `number`
local function test(var: number)
return var + 10
end
test("string") -- Type `string` could not be converted into `number`
local numbers: {number} = {5, 6, 10}
table.insert(numbers, "string") -- Type `string` could not be converted into `number`
It acts as a powerful linting tool where you can specify what type a variable is. You can add this in variables, function parameters, tables, and other things. It also autocompletes specific properties or functions that you can use based on what type annotation you specified.
Since .Touched is an RBXScriptSignal, you can use an in-built function (:Wait()) that specifically yields until that signal has been fired. You can read more about signals here.
function()
local triggerfunction = false
for i,v in pairs(table1) do
if v == "A" then
triggerfunction = true
part.Touched:Wait()
warn(".touched has been fired!")
end
end
end