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

How do i check to see if a dictionary contains a certain value?

I have two scripts, a server script in the ServerScriptService, and a local script in the StarterGui. I want to make it so the server script creates the global dictionary while the local script finds to see if a value is apart of that dictionary, and if so, it will run something.

Server Script (ServerScriptService)

_G.Inventory = {

	BodyTypesOwned = {"DefaultBody"},
	BodyColorsOwned = {"2", "3"}

}

Local Script (PlayerGui)

if _G.Inventory.BodyTypesOwned["DefaultBody"] then
	print("Found")
else
	BodyTypeFrame.BuyButton.TextButton.Text = print("Not Found")
end

1 answer

✓ Accepted answer

ModuleScript (ReplicatedStorage)

local module = {}

module.BodyTypesOwned = {"DefaultBody"}
module.BodyColorsOwned = {"2", "3"}

return module

LocalScript (PlayerGui)

local modScr = require(game.ReplicatedStorage.ModuleScript)

if modScr["BodyTypesOwned"][1] == "DefaultBody" then
	print"found"
else
	--BodyTypeFrame.BuyButton.TextButton.Text = "Not Found"
end

Your method wont work because the only "person" who can see a ServerScript is the server.

Now to explain what I did. The ModuleScript is in ReplicatedStorage because (in its name) its replicated to both client and server, so both parties can see it. The LocalScript just gets what's in the ModuleScript. If you need more of an explanation just tell me.

1 comment

0

Thanks!

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