Been stuck on this for a while, but I have a RemoteFunction
that invokes to the client and runs a bunch of different stuff before returning back to the Server.
I want this function to return instantly if the Magnitude
between this NPC, and the Player is more than 10. I have all that set up, and I’m using a connection to be able to Disconnect the function once it’s complete.
The problem is; When I return "Timedout"
, it returns "Timedout"
back to what was calling the function, not back to the server if you know what I mean. Don’t know how to explain it well, but it’s not returning it back through the RemoteFunction to the server. See the script for more info.
-- .OnInvoke event somewhere up here ^^
local MaxDistance = 10
local MovingConnection
local function PlayerMoving()
local Magnitude = (CustomerRoot.Position - Character.HumanoidRootPart.Position).Magnitude
print(Magnitude)
if Magnitude > MaxDistance then
task.delay(1, function()
task.wait()
MovingConnection:Disconnect()
end)
return "Timedout"
-- definitely not the best way to do this, but the delay is to stop...
-- the function from being disconnected before I'm able to return
-- so I delay a second on a new thread, then it returns and will disconnect the function
-- if you have any better ideas on how I can do this, let me know please~~
end
end
MovingConnection = Character.Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(PlayerMoving)
-- a bunch of other code following this, which I want to continue to run