I want to be able to retrieve a string value from a remote-function
What is the issue?
the remote function is returning nil
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)