So I'm making a script where if a model's health hits 0, the script resets the game. But the script is skipping the line where it makes the model's health 5000. Help~!
Also another script I had that uses this kinda code works fine, it's just this one..
game.Workspace.Helicopter_.Humanoid.Died:Connect(function() game.Workspace.Intel.IntelBlock.Transparency = 0 game.Workspace.Intel.IntelBlock.CanCollide = true game.Workspace.Intel.IntelBlock.ClickDetector.MaxActivationDistance = 8 game.Workspace.Intel.GUI.BillboardGui.TextLabel.Text = "Intel" game.Workspace.Helicopter_.Humanoid.Health = 5000 -- skips this line print("yesssss") for _, v in pairs(game.Players:GetChildren()) do v:LoadCharacter() end wait(.1) game.ReplicatedStorage.IntelStolen:FireAllClients() for _, v in pairs(game.Workspace:GetChildren()) do if v.Name == "Russian Soldier" or v.Name == "American Soldier" then v:Destroy() end end wait(.1) for _, v in pairs(game.Workspace:GetChildren()) do if v.Name == "Ragdoll_" then v:Destroy() end end wait(3) for _, v in pairs(game.ServerStorage:GetChildren()) do if v.Name == "Russian Soldier" or v.Name == "American Soldier" then local klone = v:Clone() klone.Parent = workspace wait(.1) end end print("?????????") end)
This is happening because the script doesn't skip the line, but the humanoid is dead and it's health can't be changed anymore as far as I know, instead clone the model at the start of the script and parent the model to workspace after destroying the original, the edited code:
clonedmodel = game.Workspace.Helicopter_:Clone() game.Workspace.Helicopter_.Humanoid.Died:Connect(function() game.Workspace.Intel.IntelBlock.Transparency = 0 game.Workspace.Intel.IntelBlock.CanCollide = true game.Workspace.Intel.IntelBlock.ClickDetector.MaxActivationDistance = 8 game.Workspace.Intel.GUI.BillboardGui.TextLabel.Text = "Intel" game.Workspace.Helicopter_:Destroy() local clonedmodel2 = clonedmodel:Clone() clonedmodel2.Humanoid.Health = 5000 clonedmodel2.Parent = game.Workspace print("yesssss") for _, v in pairs(game.Players:GetChildren()) do v:LoadCharacter() end wait(.1) game.ReplicatedStorage.IntelStolen:FireAllClients() for _, v in pairs(game.Workspace:GetChildren()) do if v.Name == "Russian Soldier" or v.Name == "American Soldier" then v:Destroy() end end wait(.1) for _, v in pairs(game.Workspace:GetChildren()) do if v.Name == "Ragdoll_" then v:Destroy() end end wait(3) for _, v in pairs(game.ServerStorage:GetChildren()) do if v.Name == "Russian Soldier" or v.Name == "American Soldier" then local klone = v:Clone() klone.Parent = workspace wait(.1) end end print("?????????") end)
Are you sure it's actually being ignored?
Just making sure, what is the humanoid's max health set to? Because the humanoid's health cannot go beyond its max health.
So if the humanoid's maxhealth is 100 (which i believe it is by default), setting the humanoid's health straight to 5000 isn't going to do anything.
You don't need to change the MaxHealth and change the Health value. Because the MaxHealth doesn't make the model's health do anything.
If this helps, or have questions, ask below.