Forum > Coding >

What do these codes do?

Posts: 17

Threads: 10

Joined: Jan, 2021

Reputation: 0

Posted

I've seen some codes like:

  • FindFirstChild
  • Fire...
  • Invoke...

What do these codes do?

Where can I use them?

Which one can I use in what kind of script?

 

Please give some information.

  • 0

I’m not lazy, I’m just on energy saving mode.

MINISHXP

minishxp

Posts: 813

Threads: 5

Joined: Jan, 2021

Reputation: 9

Replied

 
im i dont reeally know lua but for example:
 
if you theres an object with a parent and you dont kow the name of the object but know the name of tyhe parent you can do:
local THE_CHILD = OBJECT_THAT_IS_THE_PARENT:FindFirstChild(); im not sure but that kinda like that
 
 

 

  • 0

hi123

Posts: 17

Threads: 10

Joined: Jan, 2021

Reputation: 0

Replied

@_realnickk thanks for your great explanation. Is it possible to acces a game developer's moderator gui with a script like this. 

 

 

  • 0

I’m not lazy, I’m just on energy saving mode.

Explanation

Outflown

Posts: 714

Threads: 138

Joined: Nov, 2020

Reputation: 6

Replied

Simple Explanation:

 

FindFirstChild: can be used in an if statement, tries to find whatever is called, if not then false

 

example:

if (workspace:FindFirstChild("RandomPart") then

--random code

end

 

Fire: used for remoteevents, used to actually turn on the remoteevent.

 

example:

local revent = workspace.RemoteEvent

revent:FireServer(script.name)

 

Invoke: i dont actually know what this means so ill let roblox developer studio handle this

Invoke will call the OnInvoke callback and return any values that were returned by the callback (if any). If the OnInvoke callback is not set, this method will yield until one is set. If OnInvoke yields, this method will also yield. There are limitations on the values that can be sent as arguments; see the code samples.

 

example:

  1. local bf = script.Parent
  2.  
  3. -- Define a function for use with the BindableFunction
  4. local function AddTwoNumbers(a, b)
  5. return a + b
  6. end
  7.  
  8. -- Set the OnInvoke callback to be our function
  9. bf.OnInvoke = AddTwoNumbers
  10.  
  11. -- Invoke the BindableFunction
  12. print(bf:Invoke(25, 44))

 

 

 

  • 0

I am an artist.

Posts: 33

Threads: 10

Joined: Jan, 2021

Reputation: 0

Replied

I've seen some codes like:

FindFirstChild

Fire...

Invoke...

What do these codes do? Where can I use them? Which one can I use in what kind of script?

So, let's start off with the first function you listed.

Instance<T>:FindFirstChild(<string> ChildName) is an example of the first one lets say we had a hierarchy such as this one:

https://cdn.discordapp.com/attachments/806571765396144228/807238618619969606/ColorPart_explorer.png

ColorPart is the parent of the child (ColorChangeScript), that may sound like nothing if you're new, but you'll learn how parents of children work in lua.

In this case, we'd do this:

local colorchangescript = workspace:FindFirstChild("ColorPart") -- Will get the script under the part as a child.

Hope this helps, and now we should do Fire in lua! Here's the function desc: BindableEvent<T>:Fire(<string> Scriptname)

Example:

 local binding_event = script.Parent

 

local function event_temp(...) -- Define a simple function to connect to the env

print(...)

end

 

binding_event.Event:Connect(event_temp)

Too lazy to do invoke, but hope this helps.

 

  • 0

"Sometimes, giving up is better than trying for hours to achieve nothing."

- Xeon, 2021

To know where you're headed, you must know where you been.
Life is like a pear, except the pear is not real.

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )