Am I using return okay?

Well, recently I saw that in GlobalDataStore, instead of calling something with nil, they use return to get the data. I wanted to try with return but I don’t know if it’s ok, I still don’t know how to use return and I’m just relying on the link I put earlier. Am I using it well?

local success, KeyInfo = pcall(function()
	return configurationsData:GetAsync(player.UserId)
end)
if success then
	GraphicsFolder:WaitForChild("Shadow").Value = KeyInfo.shadows
	shadowSettings[KeyInfo.shadows ](player)
	GraphicsFolder:WaitForChild("Water").Value = KeyInfo.water
	waterSettings[KeyInfo.water](player)
	GraphicsFolder:WaitForChild("Tree").Value = KeyInfo.tree_texture
	treeSettings[KeyInfo.tree_texture](player)

	GameFolder:WaitForChild("FPS").Value = KeyInfo.fps
	ViewFPS[KeyInfo.fps](player)
	GameFolder:WaitForChild("Ping").Value = KeyInfo.ping
	ViewPing[KeyInfo.ping](player)
	GameFolder:WaitForChild("BrilloVol").Value = KeyInfo.gamma
	VolumenDeBrillo["Gamma"](player, KeyInfo.gamma)
	GameFolder:WaitForChild("PlayerChose").Value = KeyInfo.friends
	LumberDrop[KeyInfo.friends](player)
	GameFolder:WaitForChild("Language").Value = KeyInfo.language
	LanguageConfg[KeyInfo.language](player, "PlayerAdded")
	GameFolder:WaitForChild("SlotsInventory").Value = KeyInfo.SizeSlots
	SlotsInventory["SlotsSize"](player, KeyInfo.SizeSlots)

	KeysFolder:WaitForChild("Crouch").Value = KeyInfo.crouch
	CrouchKey[KeyInfo.crouch](player)
else

Uhm… test it and see if it works.

1 Like

From what I tested, this should work. Although, I am no expert.

1 Like

How pcalls work is they basically catch any errors that might arise. One of the variables will be a Boolean that becomes true or false depending on whether or not the function call is successful.

The second variable will contain the value returned by the function call, which is where the return comes in. You basically do whatever you want in the function and use return to we’ll return whatever value is outputted.

For example, if you wanted your function in the pcall to add 3 to any values passed in, the return would be the value after 3 is added to it.

The way you implemented the call looks correct but I didn’t test it so you need to do that part.

Hope this helps explain returns in Pcalls a bit. It’s a very simplified explanation but it should cover the basics.

1 Like