Basically I am writing a script for my boat and when I try invoking the remote function the client side function never gets called. There are no errors. I pasted the code below that directly relates to the remote function. I tried printing the playerOnWheel and checked the location of the remoteFunction and they both seem to work fine.
Server Script
while playerOnWheel ~= nil do
--get player input
local inputs = nil --safe invoke mousePosition (from commitblue)
local timeoutcount = 0
local timeout = 3
task.spawn(function()
inputs = getInputs:InvokeClient(playerOnWheel)
end)
repeat task.wait(1) timeoutcount += 1 until timeoutcount >= timeout or inputs ~= nil
print(inputs)
end
Client Script
getInputEvent.OnClientInvoke = function(player)
print("working")
local currentInputs = uis:GetKeysPressed()
return currentInputs
end
any help or ideas are appreciated
1 Like
This does not work because task.spawn() does not create a loop, it creates a thread. task.spawn() creates a thread that will run alongside the main thread. The thread inside of task.spawn() only runs once so without loops it will end.
I recommend either creating a loop that checks inputs until a player leaves the wheel or creating a remote event that can be fired from the boat, that returns keys pressed and keys released.
If you would like to learn more i recommend you start here:
1 Like
It is running within the while loop that repeats while the player is on the wheel. The loop works as intended the issue is that within the thread, when the getInputs:InvokeClient(playerOnWheel) is run the local script that is supposed to be triggered doesn’t trigger at all. I have used this same safe invoke script for remote events before so i’d assume it would work here as well.
1 Like
Have you received any errors in the console? Do either of these print statements return the desired values? Or even print at all for that matter?
1 Like
I actually figured out that the reason the script wasn’t being invoked was because it was in workspace instead of starterplayerscripts. For some reason when I run the :GetKeysPressed()
its returning an empty table even when I am pressing button although this is a different issue now.
1 Like
Ah, yeah i wouldn’t have figured that out
1 Like