I’m looking for ways to abbreviate & simplify my form of coding – I’m currently looking for a way to Gloablize Instances…
By this I mean rather than passing values from one Module to the next they’re readily available to be called on when needed.
I’ve attached below an example of my current layout, however as you can see I keep “Wand”, “Player” etc empty so that they can be filled when needed - Though, I’ll need to do this for each script.
Is there a way I can do this so I can just simply do :GetWand() or something?
I’ve heard OOP is a way to do this however I haven’t the faintest idea.
Thank you.
local Core = {Server = game, Self = script}
local Player
local Character
local Wand
local Origin, Direction
local CastEvent = Core.Self:WaitForChild("CastEvent")
local BlockEvent = Core.Self:WaitForChild("BlockEvent")
local Spell = {...}
for __,Obj in pairs (Core.Self:GetDescendants(...)) do
if Obj:IsA("ModuleScript") and Obj.Parent:IsA("Folder") then
Spell[Obj.Name] = require(Obj)
end
end
CastEvent.OnServerEvent:Connect(function(Caster, Type, i, ...)
Player = Caster
Character = Player.Character
Wand = i.Wand
Origin, Direction = i.Origin, i.Direction
if Type == "Ignite" then
Spell[i.Spell]:Ignite(...)
end
end)
return Core