Alrighty what an I doing wrong exactly. I’m trying to make my heath go from inf back to normal aka 100.
None of the scripts worked y’all put on here. And I’m not going to use Ortinium Solution because my GUI Is set up totally different
Not to be mean or anything if you don’t know the answer please don’t respond or post anything at all. I rather someone know the answer this post a bunch of scripts that didn’t work. Like on this. And if you do think you know the answer test the script before you post on here please because I literally just wasted my time adding the scripts in my thing and come to find out they do not work.
Each time you’re clicking the button, you make another connection, which doesn’t override the old one.
I think the right way is this:
local alreadyClicked = false
script.Parent.MouseButton1Click:Connect(function()
if alreadyClicked then
game.Players.LocalPlayer.Character.Humanoid.Health = 100
alreadyClicked = false
else
game.Players.LocalPlayer.Character.Humanoid.Health = math.huge
alreadyClicked = true
end
end)
So what it does is when the player clicks the button, it changes alreadyClicked to true. alreadyClicked is already false, so this should work.
The button checks if alreadyClicked is true,
if it is, set the player’s health back to 100, then set alreadyClicked to false.
If alreadyClicked already is false, then set the player’s health to inf, then set alreadyClicked to true,
db = true
script.Parent.ClickDetector.MouseButton1Click:Connect(function()
if db == true then
db = false
game.Players.LocalPlayer.Character.Humanoid.MaxHealth = max.huge
elseif db == false then
db = true
game.Players.LocalPlayer.Character.Humanoid.MaxHealth = 100
end
end)
Creating a second Connection won’t make it work, because what would be happening is:
When player fires the first event:
1. Makes MaxHealth infinite
2. Creates a connection, which of course isnt fired
When player fires the same event again:
1. The second connected event for some reason fired first, making the MaxHealth 100
2. The first event fired second, making the MaxHealth infinite again
3. A new connection is made
repeat
For some odd reason, the first connected event is fired last, making the MaxHealth infinite again after it being 100.
@lordmochibi solution would work, but here is something simplir
local humanoid = game.Players.LocalPlayer.Character.Humanoid
script.Parent.Touched:Connect(function()
humanoid.Health = humanoid.Health==math.huge and 100 or math.huge
end)
It’s supposed to be this way IIRC, the callbacks you pass to r.Event:Connect() through multiple listeners will run in reverse order (the last one runs first).
@Seranok: RBXScriptSignal used to have connectFirst and connectLast members but they were deprecated. In general if you want something to run before/after certain listeners you should make that explicit (e.g. a listener fires a BindableEvent after it is done processing)
All listeners are fired in the same frame so later listeners would be fired before any asynchronous operations