Hey, so i need some help in accesing the table containing the functions in OOP.
I’ve got a piece of code in OOP which creates like moves and it stores the keybind data/function in a folder for it to be accessed but i want the functions to be ran from a different script instead of the script which has the function created.
Here’s my script which has all the moves stored in it:
local a=game.StarterGui.Moves
local creator = require(a)
local player = game.Players.LocalPlayer
local char = player.Character
local humanoid = char:WaitForChild("Humanoid")
local test1 = creator.new("TestMove",function()
humanoid.WalkSpeed = 0;
end, "E")
Now here is the script which detects when the move has been ran:
local movesFolder = game.ReplicatedStorage:WaitForChild("MoveInfo")
local a=game.StarterGui.Moves
local creator = require(a)
local UIS = game:GetService("UserInputService")
function ts(a)
return tostring(a)
end
UIS.InputBegan:Connect(function(b,g)
if g then return end
for i,v in pairs(movesFolder:GetChildren()) do
local t = game.HttpService:JSONDecode(v.Value)
local y = ts(b.KeyCode)
if t[1] == y:sub(14,#y) then
print("Yes",v.Name)
local n = t[4]
for i,v in pairs(n) do
print(i,v)
end
--creator:run(n)
end
end
end)
As you can see i have it tagged but i want it to run the moves function after the keybind has been pressed which works fine; i don’t know if this is possible but im guessing it is.
And here’s my oop script if you were wondering:
local moves = {}
moves.__index = moves
local folderInfo = game.ReplicatedStorage.MoveInfo
function moves.new(moveName,func,button)
local m = {}
setmetatable(m,moves)
m.move = moveName
m.f = func
m.Button = button
local moveInfo = Instance.new("StringValue",folderInfo)
moveInfo.Value = game.HttpService:JSONEncode({button,moveName})
moveInfo.Name = moveName
return m
end
function moves.run()
end
function moves:debug()
self.f()
end
return moves
If you didn’t already understand what im trying to do here, then maybe this would explain it better.
I want to create a move using my oop script in one script along with the keybind and function which i want it to run after the keybind has been pressed.
I detect the keybind press from a different script and want to run the function from that script but i have no idea how that would be done.
Hope that made more sense.