So lets say I wanted to create a ModuleScript to return a table of variables for services (and potentially other things) and publish it onto the site (which I do indeed want to do):
-- izza called "Services!" :P
local _S = {}
function _S:new(self, v, s) -- this is just here, idk
self.v = game:GetService(s)
end
do -- this is just to help compile it in the scripting editor
_S.CollectionService = game:GetService("CollectionService")
_S.Players = game:GetService("Players")
_S.GetPlayers = _S.Players:GetPlayers()
_S.ReplicatedStorage = game:GetService("ReplicatedStorage")
_S.PhysicsService = game:GetService("PhysicsService")
_S.RunService = game:GetService("RunService")
_S.HeartbeatWait = game:GetService("RunService").Heartbeat:Wait()
end
return _S
You might notice that there is no _S.RenderSteppedWait.
That's because:
#RenderStepped can only be used with LocalScripts
But what if I wanted that?
_S.RenderSteppedWait = _S.RunService.RenderStepped:Wait()
But I can only do that with LocalScripts. And it's not like getfenv(2).className is gonna help me here cuz ayy guess wat
##DAT'S TARGETING A VARIABUL
How am I supposed to tell if the script is a LocalScript or a regular script so that the module script knows whether or not to pop in _S.RenderSteppedWait?
RESPONSE:
Weird....
game:GetService("RunService"):IsClient() seems to always be returning true...
This is the code I'm using to test:
-- The ModuleScript, a.k.a. game.Workspace.LeModule
local RunService = game:GetService("RunService")
local function thing() -- test #1
local OtherScriptName = getfenv(2)["script"].Name
if getfenv(2).script.ClassName == "LocalScript" then
print("LeModule was just called by the LocalScript "..OtherScriptName..", running from player "..tostring(RunService:IsClient()).."!")
else
print("LeModule was just called by the server script "..OtherScriptName.."!")
end
end
local _S = {}
if game:GetService("RunService"):IsClient() == true then
_S.test = "LocalScript"
else
_S.test = "Script"
end
return _S
-- The ServerScript for testing
workspace:WaitForChild("sweetkid01")
wait(4)
print("Server script calling...")
local thing = require(workspace.LeModule)
print(thing.test)
print("Ding!")
-- The LocalScript, a.k.a. game.StarterPlayer.StarterCharacterScripts.LocalScript. btw testing game is not filtering enabled
wait(2)
print("LocalScript calling...")
local thing = require(workspace.LeModule)
print(thing.test)
print("DingL!")
Output:
--[[
--[=[ WITH THE TABLE --]=]
> LocalScript calling...
> LocalScript
> DingL!
> Server script calling...
> LocalScript
> Ding!
--[=[ WITH THE FUNCTION (the scripts are re-formatted for this --]=]
> LocalScript calling...
> LeModule was just called by the LocalScript LocalScript, running from player true!
> DingL!
> Server script calling...
> LeModule was just called by the server script Script!
> Ding!
--]]
Why does dis happen? Is it because I'm in Studio?
edit: removed edits
edit[2]
Weird... :IsSever() also only returns "Script"...
#edit[3]
ok then i can't believe i didn't tried le working method
#edit[4]
kmn
######If this post doesn't meet any specific guideline, or you're just simply going to downvote, please comment why you're going to downvote before doing so so that I can adjust this question to be more appropriate.

8 comments
Sorry it's taking me so long, I'm testing an answer and I clearly kerfuffled with it.
ok clearly i did not kerfuffled clearly it is kerfloofled
hello?
you could check if game.Players.LocalPlayer is nil or not.
err... but then I can't manipulate the table d00d
nvm
mentally retarded is me
double mental retardationationationationationationatioantiaontaointoiatiogdknjhgbmjfd hsKLmd