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

The script I made is skipping lines. Help?

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)

3 comments

0

Are there any errors? Did you make sure that you are changing the health for the right thing?

0

Are there any errors? Did you make sure that you are changing the health for the right thing?

0

No errors.

3 answers

✓ Accepted answer

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)

2 comments

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.

0

No Problem

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.

4 comments

0

Also I recommend that you use "local intel = workspace.Intel" so that its easier to call it when finding objects in your game.

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

0

The MaxHealth is 5000. I should use variables, I just keep forgetting...

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..

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.

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