Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

RemoteEvent keeps returning nil?

Asked by 7 years ago
Edited 7 years ago

I'm testing this, because previously I tried to return a value from a table that's stored inside a datastore, but it kept on returning nil aswell. But right now, it's just supposed to return a simple string. I have no idea why this happens.

LocalScript:

local plr = game.Players.LocalPlayer
wait(1)
local text = game.Lighting.Remotes.GetName:FireServer(script.Parent.Slot.Value)
wait(1)
print(text)

ServerScript:

game.Lighting.Remotes.GetName.OnServerEvent:connect(function(plr, slot)
    local ds = game:GetService("DataStoreService"):GetDataStore("datastore["..slot.."]"..plr.UserId)
    local key = "key"..plr.UserId
    ds:GetAsync(key)
    return "Test"
end)

1 answer

Log in to vote
0
Answered by 7 years ago

If you want to return a value from the server side to the local script while the game has FilteringEnabled set to true you should try a RemoteFunction instead of an Event. "The primary difference is that RemoteFunctions allow a value to be returned after the function call, which allows for communication back to the server or client."

0
Yes, someone else had already answered that before, but i'll accept anyways. Operation_Meme 890 — 7y
Ad

Answer this question