i wont the players health to go by 50 for every lvl up the player gets
game.Players.PlayerAdded:Connect(function(player) script.Parent.Humanoid.MaxHealth = 50 * player:WaitForChild('Stats').Level.Value -- this is max health script.Parent.Humanoid.Health = 10 * player:WaitForChild('Stats').Level.Value -- this will be how much health when player join end)
something like this?
player.Stats.Level.Changed:Connect(function(player) player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth + 50 end)
this is my stats code
local DataStore = game:GetService("DataStoreService") local Data_Key = 0 local Level_Data = DataStore:GetDataStore("Level"..Data_Key) local Exp_Data = DataStore:GetDataStore("Exp"..Data_Key) local Strength_Data = DataStore:GetDataStore("Strength"..Data_Key) local Defense_Data = DataStore:GetDataStore("Defense"..Data_Key) local Stamina_Data = DataStore:GetDataStore("Stamina"..Data_Key) local DevilFruit_Data = DataStore:GetDataStore("DevilFruit"..Data_Key) local DevilFruit_Owned_Data = DataStore:GetDataStore("Owned_DevilFruit"..Data_Key) local SkillPoint_Data = DataStore:GetDataStore("SkillPoint"..Data_Key) local Start_Level = 1 game.Players.PlayerAdded:Connect(function(Player) local UserId = Player.UserId local Stats_Folder = Instance.new("Folder",Player) Stats_Folder.Name = "Stats" local Level = Instance.new("IntValue",Stats_Folder) Level.Name = "Level" Level.Value = Level_Data:GetAsync(UserId) or Start_Level local Exp = Instance.new("IntValue",Stats_Folder) Exp.Name = "Exp" Exp.Value = Exp_Data:GetAsync(UserId) or 0 Exp.Changed:Connect(function() if Exp.Value >= 500*Level.Value then Exp.Value = 0 Level.Value = Level.Value+1 end end) local Str_Stats = Instance.new("IntValue",Stats_Folder) Str_Stats.Name = "Strength" Str_Stats.Value = Strength_Data:GetAsync(UserId) or 0 local Def_Stats = Instance.new("IntValue",Stats_Folder) Def_Stats.Name = "Defense" Def_Stats.Value = Defense_Data:GetAsync(UserId) or 0 local Stamina_Stats = Instance.new("IntValue",Stats_Folder) Stamina_Stats.Name = "Stamina" Stamina_Stats.Value = Stamina_Data:GetAsync(UserId) or 0 local DF_Stats = Instance.new("IntValue",Stats_Folder) DF_Stats.Name = "DF" DF_Stats.Value = DevilFruit_Data:GetAsync(UserId) or 0 local Skill_Point_Stats = Instance.new("IntValue",Stats_Folder) Skill_Point_Stats.Name = "SkillPoint" Skill_Point_Stats.Value = SkillPoint_Data:GetAsync(UserId) or 0 local DF_Owned = Instance.new("StringValue",Stats_Folder) DF_Owned.Name = "DF_Owned" DF_Owned.Value = DevilFruit_Owned_Data:GetAsync(UserId) or "None" end) game.Players.PlayerRemoving:Connect(function(Player) local UserId = Player.UserId local Stats_Folder = Player:WaitForChild("Stats") local Level = Stats_Folder:WaitForChild("Level") local Exp = Stats_Folder:WaitForChild("Exp") local Strength = Stats_Folder:WaitForChild("Strength") local Defense = Stats_Folder:WaitForChild("Defense") local Stamina = Stats_Folder:WaitForChild("Stamina") local DF_Stats = Stats_Folder:WaitForChild("DF") local DF_Owned = Stats_Folder:WaitForChild("DF_Owned") local Skill_Point = Stats_Folder:WaitForChild("SkillPoint") Level_Data:SetAsync(UserId,Level.Value) Exp_Data:SetAsync(UserId,Exp.Value) Strength_Data:SetAsync(UserId,Strength.Value) Defense_Data:SetAsync(UserId,Defense.Value) Stamina_Data:SetAsync(UserId,Stamina.Value) DevilFruit_Data:SetAsync(UserId,DF_Stats.Value) DevilFruit_Owned_Data:SetAsync(UserId,DF_Owned.Value) SkillPoint_Data:SetAsync(UserId,Skill_Point.Value) end)
So you have a few issues. A big one being you're not using datastores, if you don't know what those are, they're what saves your player data so when they leave and rejoin, all of their money/health/level doesn't get set to 0. Heres a useful video to learn about datastores: youtube.com/watch?v=DkYupSBUpes
I'm not going to teach you about datastores, but I will tell you how to make the players health increment.
Another small thing is that you're not using variables, which bugs me a little bit.
1.
Add a RemoteEvent in ReplicatedStorage
2.
Add the script into ServerScriptService
3.
Add the local script into StarterPlayer>StarterPlayerScripts
Script in ServerScriptService
-- Gets the remoteEvent. local ReplicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = ReplicatedStorage:WaitForChild("remoteEvent") -- Sets the data. game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) remoteEvent.OnServerEvent:Connect(function(player, level) local humanoid = character:WaitForChild("Humanoid") local moneyPerLevel = 50 -- Variable incase you want the players health to go up by more than 50. local function update() -- Made a function in case if you want other things to happen when they level up. humanoid.MaxHealth = moneyPerLevel * level end update() print("Players MaxHealth: "..humanoid.MaxHealth) -- Debugging... end) end) end)
Above, is the setter. Like its name, it will set the data. Meaning, it changes the health to what it is supposed to be at.
Local Script in StarterPlayer>StarterPlayerScripts
local player = game.Players.LocalPlayer -- Gets the remoteEvent. local ReplicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = ReplicatedStorage:WaitForChild("remoteEvent") -- Gets the level. local statsFolder = player:WaitForChild("Stats", 100) local level = statsFolder:WaitForChild("Level") -- Fires it so the data doesn't equal 0. remoteEvent:FireServer(level.Value) -- Checks if the value changed, if so, fire the remoteEvent. level.Changed:Connect(function() remoteEvent:FireServer(level.Value) end)
Above is the getter. I don't think I need to explain how this works, it's just the opposite of the Script...
I hope this helped you, if it did, please mark this as the accepted answer to help other people. If you have any questions then comment!
ALSO: I recommended renaming your stats folder from Stats, to leaderstats. So you can use the built-in Roblox leaderboard...