Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to call function in a local script from another local script?

Asked by 7 years ago
Edited 7 years ago

I'm having trouble getting a normal object orientation on the client, so how to do it:

local script1

function eat()
    --body of the function
end

local script2

function sit()
    --body of the function
end

local script3

function doingSomemthing(desition)
    if desition then
        script1.eat()
    else 
        script2.sit()
    end
end

NOTE: this is in the same player

Any help will be appreciated

1 answer

Log in to vote
2
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

Use BindableEvents. They're really easy to use.

Script 1

BindableEvent.Event:Connect(function(arg)
    print(arg) --> Prints Hello.
end)

Script 2

BindableEvent:Fire("Hello")

You can also return things easily.

Script 1

BindableEvent.Event:Connect(function(Num1,Num2)
    return (Num1 + Num2)
end)

Script 2

print(BindableEvent:Fire(5,10)) --> 15
0
Note that bindableEvents, unlike RemoteEvents, are not sever-client compatible. BindableEvents can only do server to sever, and localplayer to localplayer (only the same player) RubenKan 3615 — 7y
Ad

Answer this question