RemoteFunction returning "nil" from a string value

  1. What do you want to achieve?

I want to be able to retrieve a string value from a remote-function

  1. What is the issue?

the remote function is returning nil

  1. What solutions have you tried so far?

i have tried looking on the devforum but none of it explained my problem

remote function script:

local GetCar = game.ReplicatedStorage.RemoteFunctions:FindFirstChild("GetCarStats")

GetCar.OnServerInvoke = function(player,carName,stat)
	
	local Car = game.ServerStorage.Cars:FindFirstChild(carName)
	
	if stat == "Power" then
		return Car.DriveSeat.Power.Value
	elseif stat == "Price" then
		return Car.DriveSeat.Price.Value
	elseif stat == "CarName" then
		return Car.DriveSeat.CarName.Value
	end
end

local script:

local GetCar = game.ReplicatedStorage.RemoteFunctions:FindFirstChild("GetCarStats")


local NameValue = GetCar:InvokeServer(script.Parent.Name, "Name")
local PowerValue = GetCar:InvokeServer(script.Parent.Name, "Power")
local PriceValue = GetCar:InvokeServer(script.Parent.Name, "Price")

print(NameValue)
print(PowerValue)
print(PriceValue)

local CarName = script.Parent.CarName
local Power = script.Parent.Power
local Price = script.Parent.Price


Power.Text = PowerValue
Price.Text = PriceValue

You can’t exactly return a value back to the client once it fires a RemoteEvent

What you wanna do is have the Server fire the RemoteEvent towards the client and have the client be able to receive it

local GetCar = game.ReplicatedStorage.RemoteFunctions:FindFirstChild("GetCarStats")
GetCar.OnServerInvoke = function(player,carName,stat)
	local Car = game.ServerStorage.Cars:FindFirstChild(carName)
	if stat == "Power" then
        GetCar:FireClient(player, Car.DriveSeat.Power.Value)
	elseif stat == "Price" then
		GetCar:FireClient(player, Car.DriveSeat.Price.Value)
	elseif stat == "CarName" then
		GetCar:FireClient(player, Car.DriveSeat.CarName.Value)
	end
end

Then on the client:

GetCar.OnClientEvent:Connect(function(stat)
   local returnValue = stat -- here is the value returned
end)

but I’m using a remote function and also the first 2 values do return

You did not mention that the first two values were able to return. Next time please make sure you state important info like that

So you’re saying the values for Power and Price return but not CarName?

Can you show the localscript that invokes the server with the RemoteFunction | Roblox Creator Documentation function?

yeah, also i did say that retrieve the string value

alright, I added it to the original post

You’re passing “Name” through the LocalScript. That’s why it’s not working. Try passing “CarName”

Yeah I also noticed that, I changed it and it worked, thanks alot!

1 Like