Remote Function not firing

My problem is basically in the title,
Remote Function wont fire, click sound works but it doesn’t invoke the server.
here’s the faulty code.

Car = Object Value set to the vehicle’s model.

(CLIENT)
script.Parent.Main.REMOTEST.ToggleEngine.MouseButton1Click:Connect(function()
script.Parent.ClickSound:Play()
Car.RemoteStart:InvokeServer()
end)
_________________________________________

(SERVER)
script.Parent.RemoteStart.OnServerInvoke = function(Player)
print('remoterecieved')
end

Screenshot_1035

Please help, this has been frustrating me so much.

1 Like

To check if the function is working you could try returning a value from the function

(Client)

local var --empty variable


var = remotefunction:InvokeServer(var)
print(var)

(Server)

 remotefunction.OnServerInvoke = function(variable)
 variable = "Hello"
 return variable
 end

so this code should send an empty variable to the server, which will edit the variable to be a string: “Hello”, which is returned to the client, which prints the edited variable.

returning is really nice because once you invoke it you can just return a bool value which tells you if the car is started or not.

2 Likes

if you have a while true loop running in your code before your event/function listeners then they may not work.

so in the case that you do have a while true loop in your code, try this:

 remotefunction.OnServerInvoke = function(variable)
 variable = "Hello"
 return variable
 end

 while true do
 --stuff
 end

instead of this:

 while true do
 --stuff
 end

 remotefunction.OnServerInvoke = function(variable)
 variable = "Hello"
 return variable
 end

this might help to solve your problem as well.

3 Likes

Where is the location of the client script?

Inside a GUI that’s given by the Keyfob.

1 Like

try this:

    <Server>
    local RemoteStart = script.Parent:WaitForChild("RemoteStart")

    function RemoteStart.OnServerInvoke(Player)
    print("Remote was Recieved")
    return true
    end
2 Likes

RemoteFunctions are for the Server and Client to talk back and forth to each other. If you are just sending information to the Server and not receive back to the client, please use a RemoteEvent.

In your code, there are several concerns that I have:

script.Parent.Main.REMOTEST.ToggleEngine.MouseButton1Click:Connect(function()
script.Parent.ClickSound:Play()
local info = Car.RemoteStart:InvokeServer() -- Put this in a variable to receive information back and store it in some type of form
end)


function onPlayer() -- i have reorganized this
print('remoterecieved')
return "test" --You must return some type of value
end
script.Parent.RemoteStart.OnServerInvoke = onPlayer

--Now the variable named "info" in your localscript will now have a string value of "test". To test this out, you can print this value in the localscript (as in print(info))

I cannot edit scripts due to a 503 error, so please note that the above block of code is the client, while the code below is the server

1 Like

yeah me too, 503 error wont lemme close the bracket on that print i made xD

1 Like

Thank you, your solution worked for me! I had a loop above that Invoke.

2 Likes

I’m glad it worked!
For the future, you may want to use RemoteEvents as @Abizinho said, since it appears you don’t need to return any information to the client for your specific purpose of starting a car engine.

I’m not sure why you have the player variable in the server script. Only if you are invoking or firing client you need the player variable, just in case you didn’t know.