Can you put events in module scripts? ( OOP )

On my UIS event, the function that I wrapped with it works but the event doesn’t

--Module Script 

--Metatable
local fireball =  {}
fireball.__index = fireball

--Services 
local tweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")

--Constructor Function 
function fireball.new(size, position, color)
	local newFireball = {}
	setmetatable(newFireball, fireball)
	
	newFireball.Size = size 
	newFireball.Position = position
	newFireball.Color = color
	
	local fire = Instance.new("Part")
	fire.Material = Enum.Material.Neon
	fire.Parent = game.Workspace
	fire.Position = position
	fire.Size = size 
	fire.Color = color 
	
	newFireball.Fire = fire 
	
	return newFireball	
	
end

function fireball:Animate()
	local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Linear)
	local tween = tweenService:Create(self.Fire, tweenInfo, {Position = self.Position * Vector3.new(0, 10, 0)})
	tween:Play()	
end

function fireball:KeyInput() -- How can I put a event here??
	print("ok")
	UIS.InputBegan:Connect(function(input)
		if input.KeyCode == Enum.KeyCode.F then 
			print("Pressed F ")
		end
		
	end)
end

return fireball 

--Server Script 
--Services 
local rs = game:GetService("ReplicatedStorage")
local fireball = require(rs:WaitForChild("ModuleScript"))

--Variables 
local size = Vector3.new(3, 3, 3)
local position = Vector3.new(3, 3, 3)
local color = Color3.new(255, 0, 0)
--Constructor 
local cool = fireball.new(size, position, color)
cool:Animate()
cool:KeyInput()


I’m confused, you’re using a server script to run the :KeyInput() method?

If that’s the case, that wouldn’t work as UserInputService only runs client-sided in a LocalScript.

2 Likes

Hey I have a question?

why did you do:

newFireball.Fire = fire

I mean for what is the .Fire after the Dot?

It’s essentially creating a reference to a new object named fire (a part).

1 Like

actually, it does give me null instance

I did exactly what you did. It doesnt work
I just train my skills nothing to be worry.

For your object how did you run your method?

iceattack:Animationing() -- This one passes self automatically 

or 

iceattack.Animationing() -- If you use this one self doesn't get passed automatically

Yes, I did look at my script Sir:

try

local yourObject = iceattack.new(arg1, arg2, arg3)
yourObject:Animationing(arg1)

Still doesnt work. Maybe because TweenService does not work with self. Idk

Have you looked into this?

yea but still self does not work in my skript