Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I update the MaxHealth changing in my RPG?

  • I made a small RPG using Kitteh6660's Ultimate RPG Starter Kit v.14.2, and while it worked fine back then, eventually Roblox updated and it stopped working (at least I think it is because of an update, as many other kits have this same issue). The problem is that the player's MaxHealth seems to be locked at 100. While the healthbar does show what the player's health should be, the actual health starts at and will never exceed 100. This is most obvious when first starting the game, as a level 0 player should only start with 20 health, but the bar winds up overflowing with the reading 100/20. This also means that when the player's max health is supposed to exceed 100, it instead remains permanently partially full. Not even the healing pool can fix it. It seems that while the game can calculate what the player's MaxHealth should be, it is unable to apply it to the player character. The problem I am facing is that I cannot figure out which script is causing the issue and how to fix it (I only have a rudementary knowlege of lua coding in Roblox Studio, and parts of this kit can be pretty confusing). Below is a piece of the RPGScript (located in ServerScriptService) that I think is in charge of setting the player's MaxHealth when they first enter the game. I don't know if this is where the bug is or if it is elsewhere, but it's the best lead I've got. This glitch happend in the play mode of Roblox Studio and when the game is launched from the site*
function onPlayerEntered(newPlayer)

		--Variables folders
		local stats = Instance.new("Model")
		stats.Name = "leaderstats"

		local attrb = Instance.new("Model")
		attrb.Name = "attributes"
		
		local misc = Instance.new("Model")
		misc.Name = "Stats"
		
		local armor = Instance.new("Model")
		armor.Name = "UnlockedArmor"

		--Leaderstats variables
		local clicks = Instance.new("IntValue", stats)
		clicks.Name = "Lvl"
		clicks.Value = 1

		local clicks2 = Instance.new("IntValue", stats)
		clicks2.Name = "XP"
		clicks2.Value = 0

		local clicks3 = Instance.new("IntValue", stats)
		clicks3.Name = "Gold"
		clicks3.Value = 0

		--Attributes
		local attrb1 = Instance.new("IntValue", attrb)
		attrb1.Name = "Strength"
		attrb1.Value = Properties.StartingAttributes.Value

		local attrb2 = Instance.new("IntValue", attrb)
		attrb2.Name = "Constitution"
		attrb2.Value = Properties.StartingAttributes.Value

		local attrb3 = Instance.new("IntValue", attrb)
		attrb3.Name = "Intelligence"
		attrb3.Value = Properties.StartingAttributes.Value

		local attrb4 = Instance.new("IntValue", attrb)
		attrb4.Name = "Dexterity"
		attrb4.Value = Properties.StartingAttributes.Value

		--Other stats
		local mana = Instance.new("IntValue", misc)
		mana.Name = "Mana"
		mana.Value = 100
		
		local maxmana = Instance.new("IntValue", misc)
		maxmana.Name = "MaxMana"
		maxmana.Value = 100
		
		local equippedArmor = Instance.new("StringValue", misc)
		equippedArmor.Name = "EquippedArmor"
		equippedArmor.Value = "None"
				
		local defense = Instance.new("IntValue", misc)
		defense.Name = "Defense"
		defense.Value = 0
		
		--Unlocked armors
		local unlockedArmorLeather = Instance.new("BoolValue", armor)
		unlockedArmorLeather.Name = "UnlockedLeather"
		unlockedArmorLeather.Value = false

		local unlockedArmorChainmail = Instance.new("BoolValue", armor)
		unlockedArmorChainmail.Name = "UnlockedChainmail"
		unlockedArmorChainmail.Value = false

		local unlockedArmorBronze = Instance.new("BoolValue", armor)
		unlockedArmorBronze.Name = "UnlockedBronze"
		unlockedArmorBronze.Value = false

		local unlockedArmorIron = Instance.new("BoolValue", armor)
		unlockedArmorIron.Name = "UnlockedIron"
		unlockedArmorIron.Value = false

		local unlockedArmorSteel = Instance.new("BoolValue", armor)
		unlockedArmorSteel.Name = "UnlockedSteel"
		unlockedArmorSteel.Value = false

		local unlockedArmorMithril = Instance.new("BoolValue", armor)
		unlockedArmorMithril.Name = "UnlockedMithril"
		unlockedArmorMithril.Value = false

		local unlockedArmorAdamant = Instance.new("BoolValue", armor)
		unlockedArmorAdamant.Name = "UnlockedAdamant"
		unlockedArmorAdamant.Value = false

		local unlockedArmorDemonic = Instance.new("BoolValue", armor)
		unlockedArmorDemonic.Name = "UnlockedDemonic"
		unlockedArmorDemonic.Value = false

		local unlockedArmorBone = Instance.new("BoolValue", armor)
		unlockedArmorBone.Name = "UnlockedBone"
		unlockedArmorBone.Value = false
				
		--PvP		
		if Properties.HasPvP.Value == true then
			local clicksPvP = Instance.new("IntValue", stats)
			clicksPvP.Name = "PvP Points"
			clicksPvP.Value = 0
			
			local inPvP = Instance.new("BoolValue", misc)
			inPvP.Name = "InPvP"
			inPvP.Value = game.Workspace.GAME_PROPERTIES.GlobalPvP.Value
		end

		--Assign the folders to player.
		stats.Parent = newPlayer
		attrb.Parent = newPlayer
		misc.Parent = newPlayer
		armor.Parent = newPlayer

		clicks2.Changed:connect(function() onXPChanged(newPlayer, clicks2, clicks) end) 
		clicks.Changed:connect(function() onLevelUp(newPlayer, clicks2, clicks) end) 

		newPlayer:WaitForDataReady() -- IMPORTANT: after player.DataReady = true, it won't become false again. You need DataReady to be true for a player before you can load or save data.

		-- try loading the player's score
		LoadData(newPlayer)

		newPlayer.CharacterAdded:connect(function(c) 
			c.Humanoid.MaxHealth = (game.Workspace.GAME_PROPERTIES.StartingHP.Value) + (game.Workspace.GAME_PROPERTIES.HPPerLevel.Value * newPlayer.leaderstats.Lvl.Value) + (game.Workspace.GAME_PROPERTIES.HPPerConstitution.Value * newPlayer.attributes.Constitution.Value)
			c.Humanoid.Health = c.Humanoid.MaxHealth
		end) 
end 

function onPlayerRemoving(player)
	print("Attempting to save score for " .. player.Name)
	SaveData(player)
end

game.Players.PlayerAdded:Connect(onPlayerEntered)
game.Players.PlayerRemoving:Connect(onPlayerRemoving)

Sorry if it's a little long. You can find the kit in question at: https://www.roblox.com/library/48788197/Ultimate-RPG-Starter-Kit-v14-2

1 answer

That’s because the hp system works with the client and roblox doesn’t allow it anymore

3 comments

0

Learn how to use Remote Events or I’ll teach u (Mars #1202)

0

I looked up how to use remote events and functions, but am still a little confused. This script is located in the server script service, and I don't exactly know what about the code pertains to the client. I have an idea as to what remote events are, but I don't exactly know where to put them in the script and where to put the server side script. Do you think you could be a little more specific?

0

you do realize that HUD constantly tries to update the health right?

This discussion is preserved as it was. New answers, comments, and votes are closed.