Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

1 comment

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.