Heyo,
Ok, so before we do something,
Why do we use ModuleScripts?
Module scripts are meant to store certain values, functions and methods which could be used globally In-Game. In the script that you have given, You are trying to access the client via a Module script, which is bad way of using them.
Module scripts are just there to make your life easy so,
Here's how one could use them for...
Locally (Module scripts stored in ReplicatedStorage, so they can be accessed locally)
- A UI manipulator which will fasten stuff like, GUI fading animations or Tween effects etc.
- For Camera Manipulation, Basically you make a library with lots of methods that apply to the Camera object, inturn you can use this kind of module to work on Camera Manipulation
Server (They can be stored in ServerStorage or in your ROBLOX inventory and called via require() function)
- The game script, Controls the Map loading, Weapons etc
- For making scripts for Vehicles, or for Leaderboards
There are alot of applications of them, but you need to remember how you use them
For Example
Here's a script which will capture flag when a player touches it and then updates the GUI on his screen(Not tested in studio)
We first place a Remote event in ReplicatedStorage...
ModuleScript -- Plced inside the ReplicatedStorage so both (Client and Server) have access
local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local module = {}
module.AlertPlayer(gui, Player)
gui.Visible = true
end
module.CaptureFlag(Flag_Trigger, Player)
Flag_Trigger.Captured = true
event:FireClient(Player)
end
return module
SeverScript
local flag = game.Workspace.Part
local module = game:GetService("ReplicatedStorage"):FindFirstChild("ModuleScript")
local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
flag.Touched:connect(function(hit)
if hit and hit:FindFirstChild("Humanoid") and hit:FindFirstChild("Humanoid").Health > 0 then
local Character = hit.Parent
local Player = game:GetService("Players"):GetPlayerFromCharacter(Character)
local module.CaptureFlag(flag, Player)
end
end)
LocalScript -- Basically in the Player's GUI or in Player Object =3
local module = game:GetService("ReplicatedStorage"):FindFirstChild("ModuleScript")
local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local GUI = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):FindFirstChild("AlertGui")
module.AlertPlayer(GUI, game:GetService("Players").LocalPlayer)
Well, I know this doesn't fix your problem, but what it does is gives you an Idea on how to use the Module scripts along with Local and Serverscripts when FE is enabled, I may have rushed it a bit, or I could have solved that though Im too lazy ;-; (Lazy fox hip dance)
Anyways, Hope that helps you out in one way or the other ;)
Cheers!
2 comments
Are you require()ing this from a LocalScript or a Script?
Just a regular script