I need to change the MaxHealth of a every player 30. I put a local script in the StarterPack with this code in it.
local name = script.Parent.Parent.Parent.Name local person = game.Workspace:findFirstChild(name) wait(5) person.Humanoid.MaxHealth = 30
It's fairly simple, but it doesn't work I have no clue why, any help? What do I need to change?
First off, you have too many "parents" in your name
variable. Really, you shouldn't be accessing the player this way anyways, because it wouldn't work. It is very inefficient, here is a much better way to do it.
LocalScripts have a built in variable that only LocalScripts can use. It is game.Players.LocalPlayer
.
So, instead of finding the Player's name to find the Player, you can use LocalPlayer.
local player = game.Players.LocalPlayer if player.Character ~= nil then player.Character.MaxHealth = 30 end end
That will wait for the player's character to load, then change it's MaxHealth to 30. You don't even have to access the Player in the Workspace, only in the Players.
Figured it out, but thanks.
If anyone needs it, here:
function Added(Model) wait(5); if Model == nil then return end if Model.Name == "Humanoid" then if Model == nil then return end print("MaxHealth = 30"); Model.MaxHealth = 30; end end game.Workspace.DescendantAdded:connect(Added)
first of all u need to change ur words around a little: change person to plr
second of all u may be using the wrong type of script and if this doesnt work then it will probably be where u placed ur script... in other words ur script probably needs to be in the workspace instead of starterpack.
tip: starterpack is mostly used for items and objects u want the player to spawn with and usually does not hold scripts alone.
so ur new script should look somehting like this:
local name = script.Parent.Parent.Parent.Name
local plr = game.Workspace:findFirstChild(name)
wait(5)
plr.Humanoid.MaxHealth = 30
BUT I AM JUST A STARTING SCRIPTER SO THERE IS ALSO A LARGE CHANCE THIS IS NOT RIGHT!!!!!!!!!!!!