Hi,
a module script on serverscriptstorage stores infos about items, like damage,firerate and so on.. well what i want is a way so that the player can see the stats of the item when he clicks on it, ik about remote events but i dont want to use them here , an idea came up to me that the player will have a folder an it woould be parented to it, named items , each item will have different stats then the other , but i want you advices on this
You could use a RemoteFunction that will invoke the server every time that a player clicks.
Make sure to add debounces per player. I can help you write the code if you want ![]()
Place the module in ReplicatedStorage so clients can access it directly. If the data will be displayed to clients anyway there is no reason to place it in a server container
Clients have their own version of the module script idk what you’re talking about
They can’t access any values that the server puts in it
OP never specifies that he wants to update the module’s contents during runtime
Right
Read it wrong; thought it was about live players weapons stats (like how much ammo a specific player has)
@7eoeb @Giftdenz
wait im a little bit confused, lets say that you want to create items and you will create their stats , where do you put the module that hold these info,i put them on serverside since the i don’t the client to access that module script and see the values, i was thinking about remote events/functions but i realised that it could be bad for the server since imaging 5 players clicking on items to see the stats every sec
You should have a config module script on Replicated Storage that both the Server and the Client can access, the Server will hold the true values even if the client changes it for themselves. If they equip something for example, let the server validate it via a remote function, check if they have it with DataStores or something and provide the item ![]()
Here’s a config example :
return {
-- SWORDS --
["Sword"] = {
Name = "Sword",
Type = "Melee",
Description = "default weapon, whatever.",
Rarity = "Common",
}
}
Just make sure to remember this :
- In most cases, if visual, you don’t need to validate their stats every time:
— If the player wants to see a weapon’s base stats, you can just require the config module and display the stats like that, no need to validate it because it won’t affect anyone or anything else rather than themselves. IF it does affect gameplay, then you should definitely validate it though
.
this is a good setup for standard weapons,wbt if the player can modify it, like chaning damage vaalue for themselves via modifiers
Well, you could add a base damage and a level multiplier in your config:
return {
-- SWORDS --
["Sword"] = {
Name = "Sword",
Type = "Melee",
Description = "default weapon, whatever.",
Rarity = "Common",
BaseDamage = 20,
DamageMultipler = 1.5
}
}
With this setup however, you’ll need to invoke the server via remote events or just send data back to the player (their level) so that the client can calculate it themselves, or you can just calculate it from the server. Just try to use minimal events if it’s going to be activated regularly.
The thing I’m trying to say is since the config is in the Replicated Storage service, the client can look the values up, e.g the multipler and the base value for display. The server can then send the player’s level back to the client only for display. NOT gameplay.
edit : I accidentally deleted this post somehow and I reposted
thank you for your time
but what im struggling on is
;
lets say each player has this type of sword, i have 2 ideas on my mind
1.like i said before about modifiers that could change the sword’s stats
2. the sword’s stats they can be randomized for each player like basdamage can be between 10-45 and so on
now for my issue: i was planning to use this kind of module script but since each player can have different stats of the same sword i decided to go for the instanceValues method, but somewhat i find it that this method is not that good and is going to be deprecated anyways, what i want to know ( since you are good at this ) is what do most of the devs do in this kind of situation like using module script or instancevalues
Different stats of the same sword?
Can you elaborate more on that? If you need more parameters to change for player types, you can add some more stuff in the config:
You said you wanted each player’s damage to be different.
For example, you can create a table for the players in game. Then set an interval of values for your damage : 10 - 45 (you can store these in different variables) after all of this, you can create a new random data type :
local rng = Random.new() -- you can also set a seed here
local damage = rng:NextInteger(minDamage, maxDamage) -- use this for damage
This returns a random integer between min and max damage, you should use this damage variable to store the damage for the player either each hit or per session.
also, you definitely SHOULDN’T use values :
-
You should definitely stick to the config, using another method just adds extra clutter in my opinion, having a config that you can access with a single variable is far superior than referencing countless values.
-
On top of that, some client may error or just not load some values sometimes which will halt the script, requiring them to rejoin unless you have some kind of callback.
EXCEPTION : if you’re changing stuff from the server in runtime, like if you dynamically change damage, for example the player has a buff, to apply that, using a value can be more optimal than just sending data from the server to the client to visualize effects ![]()
So; with all of these claims for you not to use values to store player data, I’ll honestly be surprised if you decide otherwise, but nonetheless, It’s your choice.
like sword A
player1 will have damage of 15 of that sword
player2 will have damage of 12 and so on
lets say we created a folder parented to the player named items, that folder will have string values representing items he has by their name ( if you have another method for this i would like to hear it from you since i can’t think of any method to store their items for each one )
now everyone will have swordA but like i said that sword won’t be the same for everyone ,like player1 would have damage of 12 and player2 would have damage of 18 and so on
As I’ve told you before, you should use tables to store these types of data, check the stuff I wrote above, if you have any questions or don’t understand PLEASE tell me so I can explain it thoroughly ![]()
side note : for visuals, use the client to calculate the values and if you wanna verify the damage they deal, use the server. Events being fired when hit won’t impact your game
(performance wise) unless you do some weird script black magic.
i did read it more than twice, and yet im still struggilnig on one point how to save the stats of the items on the players if each will have different stats values of the same sword for example
also can you give me a snippet how to create the inventory (not the invetory system but a way to store these individual items that the players has rather then useing instance values)
You should either save the level of the player or the damage itself on a datastore with the key as the player and the value as the damage or make it so that the player key holds a dictionary as well which you can use to make robust and complex systems.
My advice
:
- Use the PROFILESTORE module by loleris! It’s an excellent system to save player data. But don’t use the profileStore for literally everything. Although it certainly IS capable, you shouldn’t use it besides playerdata stuff. I advise you to research proflieStores and learn the api or just open up a tutorial on YouTube or something.
it seems that u don’t quite understand my issue
it is ok i will explain it better
Say there is a Fire Sword thats its damage can be between 10-50
now obviously player 1 will have a different damage of that sword then player 2
now you see that damage value, what i want to do is a way that- when i save the string value of players holding that fire sword on their item folder) i can get their damage i can’t use this
return {
-- SWORDS --
["Sword"] = {
Name = "Sword",
Type = "Melee",
Description = "default weapon, whatever.",
Rarity = "Common",
BaseDamage = 20,
DamageMultipler = 1.5
}
}
since the basedamage will be different for each player , now thats just an example of one value,how about other values like cooldown+NumberOfUseing+damage combined, like i said this part is confusing me , i was going to instancesvalue but i saw people disagree with it to other peoples but i have seen some quite games use this method.
then i thought of useing module script but i think it would be hard to reach the damage of the player’s firesword and modify it in the future . Hope that clears it
.
Alright, that’s why I told you to use profile store, that way you can save sword stats per player, check if they have a sword data saved, if they do, use that value for the calculations, if they don’t, give them the base value?
local Items = require(game.ReplicatedStorage.Items)
-- Generate a player's unique version
local function CreatePlayerItem(itemId)
local template = Items[itemId]
return {
Id = itemId,
Damage = math.random(template.BaseDamage[1], template.BaseDamage[2]),
Cooldown = template.Cooldown,
Uses = template.Uses,
}
end
-- Example:
local playerSword = CreatePlayerItem("FireSword")
print(playerSword.Damage) --> e.g. 37
I don’t think this is what you need, but it is what you wanted ![]()
but accessing profilestore everytime to do these kind of stuff will cause issue both to the server+the data store, i have seen some quite people use the folder parented to the player how about this merhod?
Accessing the profile store won’t write anything to the datastore until you explicitly tell it to do so, so don’t worry. You definitely should use profile store if you both want to improve your skills and for the long term. Check the ProfileStore docs out.
Note : Keep in mind that the ProfileStore and DataStore are different things. ProfileStore is an expertly made module script that USES the DataStore. The base DataStore on the other hand is a Roblox API ![]()