Pretty simple, but is there any way to send info using a remote function.
I have cars in my game, and I also want the cars to be able to be purchased by the player, but I don’t want to deal with a whole lot of different remote functions, so is there a way to say that the player wants to but lets say car x, and the server will recognize that that player x wants car x, so the server will do some code that I wrote, I have this code:
local rep = game:WaitForChild("ReplicatedStorage")
local cars = rep:WaitForChild("price")
local carss = cars:WaitForChild("car")
local buy = carss:WaitForChild("buy")
local spawncar = carss:WaitForChild("spawn")
script.Parent.MouseButton1Click:Connect(function()
local newpart = buy:InvokeServer(oldvan)
end)
You can send information to the server using remote events. When checking the information on the server-side, make sure you remember the player will be the first argument that’s passed. However, the error you’ve received seems to be due to the variable “oldvan” not being defined. Keep in mind that remote event communication to the server is one-sided.
I don’t know why you couldn’t just do this with a Remote Event it’s going to do the exact same thing but your issue is that oldvan is not declared therefore there is nothing to even be sent through.
Here’s a very rudimentary example of what I think you’re trying to achieve.
-- Client --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local carFunction= ReplicatedStorage:WaitForChild("CarFunction")
local carToBuy = ReplicatedStorage:WaitForChild("car1")
script.Parent.MouseButton1Click:Connect(function()
carFunction:InvokeServer(carToBuy.Name)
end)
-- Server --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local responseEvent = ReplicatedStorage:WaitForChild("responseRemote")
ReplicatedStorage.CarFunction.OnServerInvoke:Connect(function(plr, car)
print("Server has been invoked.")
print("Player: "..plr.Name, "Car: "..car) -- Output should be Player: PlayerName Car: CarName
-- You'd probably want to handle some buying logic (checking money for example and some sanity checks but this is a very basic example.
responseRemote:FireClient(plr, --you can insert data here as well)
end) -- remember that you shouldn't invoke a client as it could be game breaking. Use a server -> client RemoteEvent instead!