Pcalls, Returns, & RemoteFunctions

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Without using bindable events on the server-end and even the client-end, is there a way my code below can yield the pcall after 5 seconds on the server-end.

  2. What is the issue? Include screenshots / videos if possible!
    Currently, I have the client detecting when 5 seconds passes and returns with a value & no client intervention is detection is connected; however, I’d prefer the Server to handle for security purposes.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried using coroutines and I wasn’t personally able to find a solution. I’ve also used task.delay; however, when I place ‘return’ inside of the delay function it returns, obviously, to the task.delay function. Is there another way I can detect the return from the task.delay?

--- What I mean by 'task,delay'
local success,scanned = pcall(function()
	task.delay(function() return true end)
	return ReplicatedStorage.Game.RemoteFunctions.LTDJob:InvokeClient(Player,Item)
end)

-- I've also done, return func() 'func is the task.delay function' or InvokeClient()
-- ;however, this does not work as well. This is where my lua knowledge stops.


--- CLIENT CODE
if Item then
				local CD = Instance.new("ClickDetector")
				CD.Parent = Item
				
				local event = Instance.new("BindableEvent")
				local function Fire()
					event:Fire()
				end
				
				task.delay(5,Fire)
				CD.MouseClick:Connect(Fire)
				
				event.Event:Wait()
				event:Destroy()
				
				return true
			end
--- SERVER CODE
					if reduceMoney() then
						local success,scanned = pcall(function()
							return ReplicatedStorage.Game.RemoteFunctions.LTDJob:InvokeClient(Player,Item)
						end)

						
						print(success,scanned)
						
						if FindItem() then FindItem():Clone().Parent = Player.Backpack end
						return true
					else
						Notify()
						return false
					end

(This is probably not overly efficient, but if all else fails, it will be usuable)

You could try using a repeat until where one of 2 variables are required for it to proceed: The value returned from the remote function, OR a timer thing goes over 5 seconds.

i.e.

local success,scanned = pcall(function()
	local RemoteValue = nil
    spawn(function()
        RemoteValue = ReplicatedStorage.Game.RemoteFunctions.LTDJob:InvokeClient(Player,Item)
    end)
    local Timer = 0
    repeat task.wait(0.1) Timer += 1 until Timer >= 5 or RemoteValue
	return RemoteValue or true
end)
1 Like

This was a lot cleaner that the ‘solution’ I had.

I changed your repeat to a while loop so it wouldn’t have to run the task.wait(0.1), ‘had to change to task.wait(1) or it’d get to 5 instantly,’ the moment Timer or RemoteValue values are met. Overall your solution was the direction I needed and I much appreciate it!

Thank you brother.

Disreguard, Im a bozo and had to change it back to repat loop.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.