How would I make these two scripts (located below) run on the server instead of the client, one of the scripts are for managing when a value (XP) equals another value (Maximum XP) then another value (Level) would increase and another value (XP) would go to zero and the other value (Maximum XP) would increase and the other script is for managing value (energy) regeneration.
Here is the scripts;
I will edit this message once my studio becomes responsive because as of right now it became unresponsive and froze.
I will probably be more in detail when you post your scripts, but what I first have to say is that you should already be managing those values entirely from the server beforehand. It could be helpful to visualize the client/localscripts as “what the player sees on their screen” so as to manage GUIs and the sort.
The information on the GUIs should be displayed by getting the data from the server with tools such as RemoteEvents
. You shouldn’t really rely on the client to have logic such as what you mentioned:
and the reason for this is that its entirely insecure and prone to exploits. If anything the client should only make visual changes from the events that fire from the server, as it detects/deals with your value changes internally.
Yeah I will post the script for some reason when I edit the energy value inside of studio my studio freezes and becomes unresponsive.
Here is the scripts;
XP Script
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Information = Player:WaitForChild("Information")
Information.XP:GetPropertyChangedSignal("Value"):Connect(function()
if Player.Information.XP.Value == Player.Information.XP.MaximumXP.Value or Player.Information.XP.Value > Player.Information.XP.MaximumXP.Value then
Player.Information.Level.Value += 1
if Player.Information.Level.Value == 1 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 2 then
Player.Information.XP.MaximumXP.Value += math.random(10, 15)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 3 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 4 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 5 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 6 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 7 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 8 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 9 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 10 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 11 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 12 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 13 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 14 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 15 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 16 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 17 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 18 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 19 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 20 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
end
if Player.Information.Level.Value == 21 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 22 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 23 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 24 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 25 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 26 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 27 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 28 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 29 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 30 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 31 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 32 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
end
if Player.Information.Level.Value == 33 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 34 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 35 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 36 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 37 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 38 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 39 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 40 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 41 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 42 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 43 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 44 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 45 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 46 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 47 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 48 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 49 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 50 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 51 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 52 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 53 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 54 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 55 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 56 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 57 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 58 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 59 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 60 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 61 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 62 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 63 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 64 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 65 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 66 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 67 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 68 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 69 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 70 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 71 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 72 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 73 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 74 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 75 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 76 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 77 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 78 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 79 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 80 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 81 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 82 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 83 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 84 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 85 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 86 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 87 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 88 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 89 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 90 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 91 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 92 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 93 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 94 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 95 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 96 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 97 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 98 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 99 then
Player.Information.XP.MaximumXP.Value += math.random(5, 10)
Player.Information.XP.Value = 0
end
if Player.Information.Level.Value == 100 then
Player.Information.XP.MaximumXP.Value = 0
Player.Information.XP.Value = 0
end
end
end)
Energy Regeneration Script
local Character = script.Parent
local Information = Character:WaitForChild("Information")
local Energy = Information:WaitForChild("Energy")
local MaxEnergy = Energy:WaitForChild("MaxEnergy")
Energy:GetPropertyChangedSignal("Value"):Connect(function()
if Energy.Value < MaxEnergy.Value then
Energy.Value += 1
repeat until Energy.Value == MaxEnergy.Value
end
end)
Also I don’t know if the energy regeneration script works or not but what I want it to do is refill the energy if it decreases from the max energy value and it’d only refill it until it equals the max energy value.
Thats alot of if statements, aside from that, what is “Player.Information.XP.MaximumXP.Value
” meant to be?
The maximum XP value is something required for the player to reach in order to level up. They can reach the maximum XP value by obtaining XP. (Maximum XP value is a child under XP value)
I just want both of those scripts inside of a server script because from my understanding I’m pretty sure those scripts would only show for the client and the server cannot read it so that is why I want it to be inside of a server script.
Yes you are precisely correct about this, I’m assuming that you are using a server sided script to create these values though right?
so the simplest solution would be to instead of using
you should write this code within the PlayerService.PlayerAdded:Connect(function(player)
line.
for example:
PlayerService.PlayerAdded:Connect(function(player)
--[[value creation stuff you already have such as:
EXP = Instance.new("IntValue",Information)
etc...
]]
--afterwards do your information event stuff:
information.XP:GetPropertyChangedSignal("Value"):Connect(function()
if Player.Information.XP.Value == Player.Information.XP.MaximumXP.Value
--etc,etc.
end)
end)
Do know that the way you are making your EXP system is not really proper
So do I place that script inside of the same server script that creates the levels/xp values?
Yes I am using a server script to create the values and place them inside of the information folder.
Yes, that is the proper way to do it from the server. Heres an example script with a much cleaner method of the EXP system you are trying to make:
--//EXAMPLE SCRIPT//
local RequiredExp = {} --{ [Level]:Exp }
local minval = 5 --starting value for first level
for level = 1, 100 do
RequiredExp[level] = minval*level
end
--With this you no longer need a "MaximumXP" value
PlayerService.PlayerAdded:Connect(function(player)
--value creation
local Information = Instance.new("Folder",player)
local XP = Instance.new('IntValue',folder)
--etc...
XP.Changed:Connect(function()
if XP.Value >= RequiredExp[Level.Value] then
Level.Value += 1
XP.Value = 0
print('Leveled up!') --no additional if statements needed
end
--this is assuming you start at level 1
end)
end)
This is the script for the creation, so would I just add everything there or?
local Players = game.Players
local Player = Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(Player)
local InformationFolder = Instance.new("Folder")
InformationFolder.Parent = Player
InformationFolder.Name = "Information"
local Element = Instance.new("StringValue")
Element.Parent = InformationFolder
Element.Name = "Element"
local Level = Instance.new("NumberValue")
Level.Parent = InformationFolder
Level.Name = "Level"
Level.Value = 0
local XP = Instance.new("NumberValue")
XP.Parent = InformationFolder
XP.Name = "XP"
local MaximumXP = Instance.new("NumberValue")
MaximumXP.Parent = XP
MaximumXP.Name = "MaximumXP"
MaximumXP.Value = 100
local Currency = Instance.new("NumberValue")
Currency.Parent = InformationFolder
Currency.Name = "Currency"
Currency.Value = 100
end)
Heres how it would look like with your script:
local PlayerService = game.Players
local RequiredExp = {} --{ [Level]:Exp }
local minval = 5 --starting value for first level
for level = 1, 100 do
RequiredExp[level] = minval*level
end
--With this you no longer need a "MaximumXP" value
PlayerService.PlayerAdded:Connect(function(player)
--value creation
local Information = Instance.new("Folder",player)
Information.Name = 'Information'
local Level = Instance.New('IntValue',Information)
Level.Name = 'Level'
local XP = Instance.new('IntValue',Information); XP.Name = 'XP'
--dont need MaximumXP anymore
--currency, element, etc...
XP.Changed:Connect(function()
if XP.Value >= RequiredExp[Level.Value] then
Level.Value += 1
XP.Value = 0
print('Leveled up!') --no additional if statements needed
end
--this is assuming you start at level 1
end)
--thats it for the level up logic
end)
Okay but would this make the player start at level 0 with 0/100 XP? (This is how my current system is)
Also what is player service, it is bringing up an error?
No, for that you would have to make these changes:
local PlayerService = game.Players
local RequiredExp = {}
local minval = 100 --starting value for first level
for level = 1, 100 do
RequiredExp[level] = minval + math.random(level,level+5)--changed
end
PlayerService.PlayerAdded:Connect(function(player)
--value creation
local Information = Instance.new("Folder",player)
Information.Name = 'Information'
local Level = Instance.New('IntValue',Information)
Level.Name = 'Level'
local XP = Instance.new('IntValue',Information); XP.Name = 'XP'
--currency, element, etc...
XP.Changed:Connect(function()
if XP.Value >= RequiredExp[Level.Value + 1] then --added +1
Level.Value += 1
XP.Value = 0
print('Leveled up!')
end
end)
end)
its the same as game.Players
, people usually call it by doing game:GetService('Players')
instead