How do I activate another script's function?

Hello! I have a little problem… You see, there is this door I have and I want it to be a part of my main menu. For example, If you press “play” the door opens, and the camera zooms goes inside the door.

Here is my problem. I want the door to open and then the camera will zoom inside perfectly timed. But, I have no idea how to do this. I do know that I need to activate this function in order for the door to open.

Here is the function I need to activate to get the door open.

local function Open()
	script.Parent.LockShowOne.BrickColor = BrickColor.new("Deep orange")
	script.Parent.LockShow.BrickColor = BrickColor.new("Deep orange")
	
	script.Parent.Frame.Union.Hydraulics:Play()
	TweenModelH(script.Parent.Hydraulics1,CFrame.new(script.Parent.Hydraulics1.Union.Position.X - 4,script.Parent.Hydraulics1.Union.Position.Y,script.Parent.Hydraulics1.Union.Position.Z),false)
	TweenModelH(script.Parent.Hydraulics2,CFrame.new(script.Parent.Hydraulics2.Union.Position.X + 4,script.Parent.Hydraulics2.Union.Position.Y,script.Parent.Hydraulics2.Union.Position.Z),true)

	script.Parent.Frame.Union.Sound:Play()
	TweenModel(script.Parent.Door,CFrame.new(script.Parent.Door.Center.Position.X,script.Parent.Door.Center.Position.Y + 8.4,script.Parent.Door.Center.Position.Z),true)

	DoorStatus = "Opened"
	script.Parent.LockShowOne.BrickColor = BrickColor.new("Bright green")
	script.Parent.LockShow.BrickColor = BrickColor.new("Bright green")
end

Here’s the local script for the ScreenGui button

local tweenService = game:GetService("TweenService")
local btn = script.Parent

function tweenCamera(pos,tweenTime)
	tweenService:Create(camera,TweenInfo.new(tweenTime,Enum.EasingStyle.Circular),{CFrame = pos.CFrame}):Play()
end

btn.MouseButton1Click:Connect(function()
	
	
	btn.Visible = false
	wait(5)
	game:GetService("TeleportService"):Teleport("")
	
	tweenCamera(mainMenuMap.CameraPart1,1)
	wait(1)
	print("Reached Destination")
end)

Thanks!

  • AstralApples
1 Like

You would use a module script to call functions from another script. I typically use module scripts for everything across scripts, like settings, variables, configs, functions, etc.

you can use modules or bindable events

ModuleScript (roblox.com)
BindableEvent (roblox.com)

You could also use _G to store the functions if you think it is more convenient than using ModuleScripts or BindableEvents

(There is a really big stigma around using _G; as long as you know what you’re doing you should be fine.)

3 Likes

The lack of autocomplete with _G derived data makes me loose my mind when using it, that is the main thing that drives me towards module scripts, not that _G is dangerous although it can be quite dangerous if you use it incorrectly.

1 Like