Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

The script I made is skipping lines. Help?

Asked by 9 months ago
Edited 9 months ago

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)
0
Are there any errors? Did you make sure that you are changing the health for the right thing? PoppyandNeivaarecute 99 — 9mo
0
Are there any errors? Did you make sure that you are changing the health for the right thing? PoppyandNeivaarecute 99 — 9mo
0
No errors. NiroTurtle 83 — 9mo

3 answers

Log in to vote
1
Answered by 9 months ago
Edited 9 months ago

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)
0
When I had this problem, I tried to clone it and I believe it worked. But thanks for telling me that you can't heal when it's dead. NiroTurtle 83 — 8mo
0
No Problem Lord_WitherAlt 121 — 8mo
Ad
Log in to vote
0
Answered by 9 months ago

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.

0
Also I recommend that you use "local intel = workspace.Intel" so that its easier to call it when finding objects in your game. Fl3eandFlo3e 18 — 9mo
0
^ this too. it's good practice to keep your code more readable and efficient, rather than having to continuously write out that line all the time plagueus 44 — 9mo
0
The MaxHealth is 5000. I should use variables, I just keep forgetting... NiroTurtle 83 — 9mo
0
Well this is interesting. The script will do anything but change the health. I tried heli.Health = heli.MaxHealth.. Nope. script.Parent.Humanoid.Health = script.Parent.Humanoid.MaxHealth. Nope. This is getting annoying.. NiroTurtle 83 — 9mo
Log in to vote
0
Answered by
Xapelize 709 Moderation Voter
9 months ago

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.

Please, please mark this answer if this worked to you! Thanks, also, this answer is just a concept to you.

Answer this question