Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

RemoteEvent keeps returning nil?

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

✓ Accepted answer

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."

1 comment

0

Yes, someone else had already answered that before, but i'll accept anyways.

This discussion is preserved as it was. New answers, comments, and votes are closed.