I posted earlier about creating a spellcasting system with OOP. I have encountered an issue with a class in which it says the Player parameter is nil even though I have defined it.
Here is the LocalScript code:
local Player = game.Players.LocalPlayer
-- Input (To Server)
UserInputService.InputBegan:Connect(function(key,chatting)
if chatting or Move_Break then return end
local B = tostring(key.KeyCode)
Move_Break = true delay(1,function() Move_Break = false end)
for i,v in pairs(MoveModules) do
local Move = require(v)
if Move.Key == B then
local NewMove = require(v)
NewMove.new(Player.Name, Move.Element, Move.Cooldown, Move.Stamina, Move.LastUsed, Mouse.Hit)
NewMove:DoMove()
end
end
end)
And this is the module:
Move = require(script.Parent.Parent.Essentials.Move)
local AirBlast = {
-- Settings
Key = Enum.KeyCode.G,
Name = "AirBlast",
Stamina = 30,
Element = "Air",
Cooldown = 6,
LastUsed = 0,
}
AirBlast.__index = AirBlast
setmetatable(AirBlast,Move)
function AirBlast.new(Player, Element, Cooldown, Stamina, LastUsed, Mouse)
local newAirBlast = Move.new(Player, Element, Cooldown, Stamina, LastUsed)
setmetatable(newAirBlast, AirBlast)
newAirBlast.Mouse = Mouse
return newAirBlast
end
function AirBlast:DoMove()
print(self.Player)
local now = tick()
if now - self.LastUsed > self.Cooldown then
self.LastUsed = now
local BodyGyro = Instance.new("BodyGyro", game.Players[self.Player].Character.HumanoidRootPart)
BodyGyro.MaxTorque = Vector3.new(0,math.huge,0)
BodyGyro.CFrame = CFrame.new(game.Players[self.Player].Character.HumanoidRootPart.CFrame.p,self.Mouse.p)
BodyGyro.P = 1e9
delay(0.3, function() BodyGyro:Destroy() end)
self.Player.Humanoid.WalkSpeed = 0
self.Player.Humanoid.JumpPower = 0
local AirBlastAn = game.Players[self.Player].Character.Humanoid:LoadAnimation(game.ReplicatedStorage.BendingResources.AirBending.Animations.AirBlast)
AirBlastAn:Play()
AirBlastAn:AdjustSpeed(1.5)
end
end
return AirBlast
Whenever :DoMove is called, self.Player is nil even though it is defined in the MainLocalScript, can anyone explain why this is happening?