Okay so I have made this script for my Role playing game to make you level up when you get 50 XP, but I want the script to also increase the max health by 50 whenever the player gets 50 XP.
function onXPChanged(player, XP, level) if XP.Value>=level.Value * 50 then XP.Value = XP.Value - level.Value * 50 level.Value = level.Value + 1 end end function onLevelUp(player, XP, level) if player.Character~=nil then for i = 1,5 do local fireworks = Instance.new("Part") fireworks.Shape = 0 fireworks.formFactor = "Symmetric" fireworks.Size = Vector3.new(1,1,1) fireworks.BrickColor = BrickColor.Random() fireworks.CFrame = player.Character.Head.CFrame + Vector3.new(0,2,0) fireworks.Parent = game.Workspace game:GetService("Debris"):AddItem(fireworks, 2) fireworks.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30)) end end local m = Instance.new("Hint") m.Parent = game.Workspace m.Text = player.Name .. "Leveled up" wait(3) m.Parent = nil end function onPlayerRespawned(player) wait(5) player.Character.Humanoid.Health = player.leaderstats.Level * 100 player.Character.Humanoid.MaxHealth = player.leaderstats.Level * 100 --[[ local stuff = player.Backpack:GetChildren() wait(5) for i = 1,#stuff do local name = stuff[i].Name if game.Starterpack:findFirstChild(name)==nil then stuff[i]:Clone().Parent = player.Backpack end end --]] end function onPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local xp = Instance.new("IntValue") xp.Name = "XP" xp.Value = 0 local level = Instance.new("IntValue") level.Name = "Lvl" level.Value = 1 local c = Instance.new("IntValue") c.Name = "Gold" c.Value = 0 xp.Parent = stats level.Parent = stats c.Parent = stats stats.Parent = newPlayer xp.Changed:connect(function() onXPChanged(newPlayer, xp, level) end) level.Changed:connect(function() onLevelUp(newPlayer, xp, level) end) newPlayer.Changed:connect(function (property) if (property == "Character") then onPlayerRespawned(newPlayer) end end) end game.Players.ChildAdded:connect(onPlayerEntered)
Thanks if you read this and double thanks if you reply.
Humanoid has both a health, and a max health value
local Humanoid = script.Parent.Humanoid function PwntX_X() local tag = Humanoid:findFirstChild("creator") if tag ~= nil then if tag.Value ~= nil then local Leaderstats = tag.Value:findFirstChild("leaderstats") if Leaderstats ~= nil then Leaderstats.Gold.Value = Leaderstats.Gold.Value + 12 wait(0.1) script:remove() end end end end Humanoid.Died:connect(PwntX_X) local healthincrease = 50 -- Change this local Humanoid = script.Parent.Humanoid function PwntX_X() local tag = Humanoid:findFirstChild("creator") if tag ~= nil then if tag.Value ~= nil then local Leaderstats = tag.Value:findFirstChild("leaderstats") if Leaderstats ~= nil then Leaderstats.XP.Value = Leaderstats.XP.Value + 8 Humanoid.MaxHealth = Humanoid.MaxHealth + healthincrease Humanoid.Health = Humanoid.Health + healthincrease wait(0.1) script:remove() end end end end Humanoid.Died:connect(PwntX_X)