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

script wont set player's health?

This level script is suppose to set the player's Health to be 10 times the level they are. So, level 2 will be 120 health. Why wont it work? I'm not getting any errors, but I have used Print, and I detailed what is printing and what isn't

script:

s = script.Parent
p = s.Parent
c = p.Character



p.Levelss.XP.Changed:connect(function()
	if p.Levelss.XP.Value >= p.Levelss.Level.Value * 20 then
	p.Levelss.XP.Value = 0
	p.Levelss.Level.Value = p.Levelss.Level.Value + 1
	p.Character.Humanoid.MaxHealth = p.Character.Humanoid.MaxHealth + 10
	p.Character.Humanoid.Health = p.Character.Humanoid.Health + 10
	p.Levelss.FAP.Value = p.Levelss.FAP.Value + 1
	end
end)


function onPlayerEntered(newPlayer) print("Added New") --wont print
	newPlayer.CharacterAdded:connect(function(c) print("Connected Character Added") --	wont print
	c.Humanoid.MaxHealth = newPlayer.Levelss.Level.Value * 10 + 100 print("Max HP set") --wont print
	c.Humanoid.Health = newPlayer.Levelss.Level.Value * 10 + 100 print ("Health set") --wont print
	end) print ("ended 1") -- wont print
end print ("ended 2") -- Prints


game.Players.PlayerAdded:connect(onPlayerEntered) print("Connected Function") -- Prints





5 comments

0

Indent your code, then we'll try and fix it lol.

0

yes, because a 26 line script needs to be indented.. Alright, I will go indent it

0

There ya go

0

Is this a LocalScript or a Script?

0

No, it's a normal script inside of the starter pack

1 answer

✓ Accepted answer

This should be a LocalScript (since you're putting in the Starterpack). The only reason it's running is because you're testing in Studio, which is a blend of Server and Client simultaneously.

Further, onPlayerEntered isn't about to run because it can't run until the LocalPlayer has already entered the game and started loading (and then running) scripts!

Just remove the onPlayerEntered event; put the code right in the initialization of the script (ie not inside any functions).

1 comment

0

Thanks!

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