local Chat = {}
Chat.__index = Chat
local ContextActionService = game:GetService("ContextActionService")
local TweenService = game:GetService("TweenService")
local TI = TweenInfo.new(0.5, Enum.EasingStyle.Circular, Enum.EasingDirection.Out)
local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
function Chat.new()
local self = setmetatable({}, Chat)
self.UI = script.ChatUI:Clone()
self.UI.Parent = Player.PlayerGui
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
return self
end
function Chat:BindToSlash()
ContextActionService:BindAction("Focus", self:Focus(), false, Enum.KeyCode.Slash)
end
function Chat:Focus(actionName, inputState, inputObject)
if actionName == "Focus" and inputState == Enum.UserInputState.End then
self.UI.Frame.InputText:CaptureFocus()
end
end
function Chat:SendMessage()
end
return Chat
at function Chat:BindToSlash, self:Focus() says its nil. Why??
Are you getting an error in the output window? If you’re only seeing a warning in the script editor this is likely just due to the current state of the Luau type solver. It does not play well with the typical implementation of Lua metatable OOP at the moment.
Oh, well self:Focus() returns a nil value (the method implementation has no return so nil is the default return. I think what you might be going for is:
function Chat:BindToSlash()
ContextActionService:BindAction("Focus", function() self:Focus() end, false, Enum.KeyCode.Slash)
end
In that example you are calling the method immediately in that line. This is perfectly valid if you want the contents of the Focus method to run when that line runs.
However, from you original issue, you need to pass a function value (ChatUI:Focus() is not a function value, it is the value returned after calling that method) as the second argument to BindAction. You don’t want to call Focus immediately when calling BindAction so instead we need to pass BindAction a function it can call (after some key is pressed). Therefore, we need to wrap the method call into an anonymous function (or one defined earlier).