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

How would I handle an ores system that all scripts understand, and link into a DataStore Inventory?

Asked by 5 years ago

Ok so, what I'd like to do in my game is have ores/trees around the map that can be found. When mined/chopped, you get some XP and 1 of said ore/log added to your inventory, which is on the server in a datastore. You can use these ores on your weapon to customize the look of it. I'm struggling with adding the inventory. I know how data stores work. My problem is actually implementing the Objects. So if I wanted to randomize the chance of an ore spawning, I'd grab a table with all the ore names, so x = ["Ruby_Ore", "Sapphire_Ore", etc], how would I tell all the scripts that might need to use the ores system, that "Ruby_Ore" means Ruby? Sorry if my question is confusing because this is my first time asking for help with something, and I don't have many ideas on how I'd approach this problem. Thanks for any help.

1 answer

Log in to vote
0
Answered by 5 years ago

You can use global tables. Example: Set the global

local Ores = {Ruby = "Ruby_Ore",Sapphire = "Sapphire_Ore"} -- etc
_G.Ores = Ores

From other script

-- example
for i,v in pairs(_G.Ores) do
-- i for index
-- v for value
-- in this case i would be Ruby Or Sapphire, the names
-- and v would be Ruby_Ore or Sapphire_Ore wich are the values set to them
print(""..i.." equals to "..v.."!")
end 

Happy scripting!

0
Would I set this script from a Server Script? Or a Local? If I set it on the server, does it replicate to the Client? pythonbites 7 — 5y
0
Nope, Set it on server and client maumaumaumaumaumua 628 — 5y
0
Ah ok, thanks for your help! pythonbites 7 — 5y
0
python, if this helped, i would highly appreciate accepting my answer :D maumaumaumaumaumua 628 — 5y
View all comments (2 more)
0
Yep, I'm just figuring out how to now lol. Also, can I call a module script that is in ReplicatedStorage that sets the global? pythonbites 7 — 5y
0
If you call it from the client, it will be called and set a client global, if called by server will set a server global. Any actions they do depends from where you are calling them, In conclusion yes maumaumaumaumaumua 628 — 5y
Ad

Answer this question