-
What do you want to achieve? I want to create a round-based system, where the last player standing wins some coins. These coins can be used to buy various magic abilites.
-
What is the issue? I’ll use number values to represent a player’s coins. However, how would both the server AND client access these? Would I use a PlayerAdded event, to create a coins value? Would I create the number values from the client, server, or both? How would I create a number value that both the server and client can access?
Also, how would I use datastores to save the data? I have no clue how to use those, or where to learn about those other than Youtube Videos and on this website…
-
What methods have you tried? I’ve tried doing PlayerAdded events on the server, but the client can’t access them. I’ve tried doing Instance.new(“NumberValue”) on both the server and client, but it doesn’t give the results I want. And I don’t think ModuleScripts or RemoteEvents will help me…
So, what should I do?
Also, sorry if the question seems elementary, i’ve only been scripting about 2-3 months now…
Yes, but this isn’t what i’m looking for.
How would the server AND client BOTH interact simultaneously (using folders/numbervalues/intvalues)
I don’t really understand?, So do u want it after the round they get money or XP?
Yes. For example, let’s say a round’s finished, and a player wins. Then, i can create a number value called XP. Then, i’ll add, say, +5 to it since they won a round.
However, the video above doesn’t show how to give players XP after they’ve completed a round. That’s what i’m trying to find.
-- Server script
game.Players.PlayerAdded:Connect(function(Player)
local XP = Instance.New("IntValue")
XP.Name = "XP"
XP.Value = 0
XP.Parent = Player
end)
-- After you find out how to finish the round type this:
for _, v in pairs(game.Players:GetChildren()) do
local Player = v
Player.XP.Value = Player.XP.Value + 50 -- How much u want the XP to go up by..., Lets say 50
end
This works also! However, there is still 1 problem:
What if I wanted to access this:
game.Players.PlayerAdded:Connect(function(Player)
local XP = Instance.New("IntValue")
XP.Name = "XP"
XP.Value = 0
XP.Parent = Player
end)
in other scripts? like say, a shop which sees if the player has enough XP to buy a magic ability?
I see you have underestimated the power of modules:
Insert a module in ServerScriptService and type:
local XPMain = {}
XP.GetValue = function(Value)
for _, v in pairs(game.Players:GetPlayers()) do
local Player = v
while true do
wait()
Value = Player.XP.Value -- Setting the value to the Paramater: "Value"
end
end
end)
-- Insert a script (normal) and say:
local Module = require(script.Module) -- Using require() makes the module run.
local ValueIndicator -- this is the variable we will use for finding out the value for XP
local XPValue = Module.GetValue(ValueIndicator)
print(ValueIndicator) -- Will print out XP.Value
Or you could just do:
-- Normal server script
for _, v in pairs(game:GetChildren()) do
local Player = v
local XPValue = Player.XP.Value
end
This works!
And I can reference it from different scripts! BUT
Theres still 1, 1 small thing
Does this have serve as any protection from exploiters? I’m not sure if this is possible, but couldn’t exploiters go to their player, their XP stats, and increase their XP to the max?
Also, I’m talking about the ModuleScript.
No, If u put it parented under the MainScript (A normal script) Exploiters just change it for there client and if u check everything ServerSided changing anything from the client is worthless.
Please, stop bumping the thread by making multiple replies, when you can just put it into one.
Also, you don’t necessarily need ModuleScripts to do all of that. If you were to make a Shop System, you would more likely do it using GUIs. If that’s the case, you can just use game.Players.LocalPlayer, and then fire a RemoteEvent, to the server. And, please, always handle it through the server! Doing so with clients can make the game very vulnerable, to potential exploiters!
Alright, thank you!
I’ll definitely use this!
However, what would I do if I wanted to add another stat? Let’s say I wanted to add another stat, like coins? How would I add this to the ModuleScript? And is their any other methods of achieving this OTHER than ModuleScripts?
What do you mean? I’m just asking a question for him to elaborate on what he’s saying.
Just copy and paste the leaderstats script and change all the names for it and inside the module script do:
XP.GetValue = function(Value, OtherValue )
for _, v in pairs(game.Players:GetPlayers()) do
local Player = v
while true do
wait()
Value = Player.XP.Value -- Setting the value to the Paramater: "Value"
OtherValue = Player.OtherValue -- What you want you're value to be .Value
end
end
end)
Also please don’t copy and paste the XP.GetValue script just add what I said inside of it.
Alrighty, I will! Also, thank you for the advice, and i’ll definitely use it in my XP system!
I wish you a good day and night, and thank you again for helping me!
1 Like