Help with ModuleScripts and StringValues

Hi.
So I was making an FPS framework for my game and I encountered this problem: Basically I have a string value inside the character with the name of the gun I want to equip at the beggining. I call it OwnedGun

Then in a local script I get that value and search for a gun model and a viewmodel named after the value. I keep the gun’s properties in a module script called “Config”. This is what it looks like:

Then in the same LocalScript I get those values:

What I want to do is get those values from above, with the OwnedGun.Value instead of Config.M4.Damage. I want to do this since the OwnedGun will be saved and I can’t equip the same gun everytime the player returns to the game.

Is it even possible?

2 Likes

I have tried this but it doesn’t work:

local CurrentAmmo = table.find(Config, OwnedGun.Value).CurrentAmmo

Try this (inside the LocalScript):

local ownedGun = "M4"
ownedGun = Config[ownedGun]

local variable = ownedGun.variable -- Replace variable with the variable you want to extract

Edit: Put the ownedGun name in quotes, or it won’t work. Also make sure you use the module script inside your LocalScript:

local Config = require(pathToModule)
1 Like

Oh wow. I haven’t thought about it being this simple. Thanks!

1 Like

It took a minute to think of something but I hope it helped!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.