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.
<Server>
local RemoteStart = script.Parent:WaitForChild("RemoteStart")
function RemoteStart.OnServerInvoke(Player)
print("Remote was Recieved")
return true
end
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’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.