Hello, So Recently I tried making an Aiming System for my Weapon, and while doing so, I stumbled Across this Error:
attempt to call a table value
Why am I getting this Error?
ModuleScript:
Weapon.ScopeData = { -- Data for FOV
Pistol = 40;
Rifle = 35;
ScopedRifle = 20;
Sniper = 10;
}
function Weapon:Scope(p: Player?,Tweenable, Type, Active: boolean?)
if Active then -- If Active is true
Weapon.Tween:Create(Tweenable, TweenInfo(.3), {FieldOfView = Weapon.ScopeData[Type]}):Play()
elseif not Active then
Weapon.Tween:Create(Tweenable, TweenInfo(.3), {FieldOfView = 70}):Play() -- error line
end
end
Code Firing the Event:
InputEnter = Weapon.UserInput.InputBegan:Connect(function(Input, gameProcessedEvent)
if Tool:GetAttribute("Active") then -- If Tool Is Active (as in Equipped)
if Input.KeyCode == Enum.KeyCode.Q or Input.UserInputType == Enum.UserInputType.MouseButton1 then
Tool:SetAttribute("Aiming", true) -- AIming is true
Weapon:Scope(Player, workspace.CurrentCamera, "ScopedRifle", Tool:GetAttribute("Aiming")) -- Applys Scope Effect
Events.Aim:FireServer(Tool:GetAttribute("Aiming")) -- Fires to Server
end
end
end)
-- same thing down here but Removing
InputEnd = Weapon.UserInput.InputEnded:Connect(function(Input, gameProcessedEvent)
if Input.KeyCode == Enum.KeyCode.Q or Input.UserInputType == Enum.UserInputType.MouseButton1 then
Tool:SetAttribute("Aiming", false)
Weapon:Scope(Player, workspace.CurrentCamera, "ScopedRifle", Tool:GetAttribute("Aiming"))
Events.Aim:FireServer(Tool:GetAttribute("Aiming"))
end
end)