Hello, Im working on a RPG-like game. Here’s my problem, I want to return true when player presses Z or Enter.
But whenever I try to return and take it from server, it gives out
nil. How can I solve that?
game.Lighting.TakeFightReturn.OnClientInvoke = function()
local Take = false
local UIS = game:GetService("UserInputService")
local Time = 150
connection = UIS.InputBegan:Connect(function(Key, Proccess)
if not Proccess then
if Key.KeyCode == Enum.KeyCode.Z or Key.KeyCode == Enum.KeyCode.Return then
local success, fail = pcall(function()
Take = true
So… what are you trying to achieve also it’s really late here and it’s night so are you trying to make it so it returns the boolean variable Take? Try printing the returned boolean and see if it prints true or false or just nil.
So, This is a kind of fight button thing, when player presses Z or Enter, it will take that as true and continue. And when I print it from server, it gives out nil. But when I print out from here, it gives true.
the inputbegan does not halt(i forget the correct word to describe this), so it returns nil.
Is there a way to do it then? I need to do this thing, and I also tried coroutine but it gave me the same result aswell.
i think most people don’t recommend sending a remote function to the client since somebody could halt that function, potentially causing problems since the server may just sit there waiting for a response.
send a event to the client, have the client send a event back to the server saying they pushed the z button
Preferably, you can use a BoolValue and yield for it to change, then return true at the end.
local bool = Instance.new("BoolValue");
--// Inside your connected function
bool.Value = true
--// Outside of it
bool.Changed:Wait(); --// On ValueBases, Changed only fires when the Value changes
FYI: your return in the connected function is only returning in that function, not the one above. This is the real reason of it not correctly functioning.
@Ocipa the word you’re looking for is ‘yield’.
Thank you both @ReturnedTrue and @Ocipa , both of the things you guys said worked, but Ocipa did reply first so, i did take his answer as solution.