Can you send info using a remote function?

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)

it says “unknown global ‘oldvan’”.

I am not good with remote functions but it may be because you haven’t specify what is “oldvan”

how would I do that? (character limit)

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.

1 Like

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.

1 Like

Try using for i, v in pairs(rep["CARS FOLDER'S NAME"]GetChildren()) for the folder where the car is and put v instead of the oldvan.

1 Like

But they are trying to get a specific vehicle and not all of the vehicles in a folder.

1 Like

yes. I want to send a string, that string will be received by the server, then ill have some if statements set up or something.

would sending a number for example the van from earlier, that would be 1, and other car would be 2? would that work?

Just change it to something like

--MAIN SCRIPT

script.Parent.MouseButton1Click:Connect(function()
    local carToSend = 'oldvan'
	local newpart = buy:InvokeServer(carToSend)
end)

Then when you check it on the other side just check for the player and the carToSend and just check if carToSend == ‘oldvan’ then

1 Like

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!

1 Like