Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The script I made is skipping lines. Help?

Asked by
niroqeo 123
4 years ago
Edited 4 years 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 134 — 4y
0
Are there any errors? Did you make sure that you are changing the health for the right thing? PoppyandNeivaarecute 134 — 4y
0
No errors. niroqeo 123 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years 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. niroqeo 123 — 4y
0
No Problem Lord_WitherAlt 206 — 4y
Ad
Log in to vote
0
Answered by 4 years 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 — 4y
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 — 4y
0
The MaxHealth is 5000. I should use variables, I just keep forgetting... niroqeo 123 — 4y
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.. niroqeo 123 — 4y
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years 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