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

How do you make a part move upwards if an npc's health is at 0?

Asked by 3 years ago
Edited 3 years ago

Hey, I'm quite new to scripting and I don't really know that much. I've been working on a dungeon-styled Roblox boss rush game where if you kill the boss (the npc) and its health is at 0, a part moves upwards which is the door and you can proceed to the next boss room. I looked for tutorials about it but I couldn't find any. Can anyone tell me how to script this, and where to put the script inside?

0
Well, nothing's health can be under zero, it can be equal to zero sne_123456 439 — 3y
0
whoops sorry i meant equal to 0 yeah 5402007 4 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Hi, to achieve this, you can constantly check if the npc's health is equal to zero and if so, you can tween to door to open.

Here's a script:

-- i made 2 bosses

local part1 = game.Workspace.Part1 -- get your 1st door
local part2 = game.Workspace.Part2 -- get your second door

local TweenService = game:GetService("TweenService") -- this is the tween for the 1st door

local part1 = game.Workspace.Part1 -- 1st door

local goal = {}
goal.Position = Vector3.new(-6.197, 22.353, -67.553) - set the position you want the door to be if it is killed.

local tweenInfo = TweenInfo.new(5) -- how long the door takes to fully open, keep it as 5 to make the tween smooth.

local tween1 = TweenService:Create(part1, tweenInfo, goal) -- give the information

local TweenService = game:GetService("TweenService") -- tween for the 2nd door

local part2 = game.Workspace.Part2 -- get your 2nd door

local goal = {}
goal.Position = Vector3.new(-23.852, 21.838, -66.892) -- set the position you want the door to be if it is killed.

local tweenInfo = TweenInfo.new(5) --how long the door takes to fully open, keep it as 5 to make the tween smooth.

local tween2 = TweenService:Create(part2, tweenInfo, goal) -- gives information

local npc1 = game.Workspace.NPC1 -- get your 1st boss
local npc2 = game.Workspace.NPC2 -- get your 2nd boss

while true do -- while true do constantly goes in a loop, therefore checking constantly if a boss is killed.
if npc1.Humanoid.Health == 0 then -- checks if 1st boss is killed
    tween1:play() -- plays the tween
end

if npc2.Humanoid.Health == 0 then -- checks if 2nd boss is killed
    tween2:play() -- plays the tween
    end
    wait() -- keeps from destroying your pc and intense lag
end

Hope this helped!

Any questions? just ask!

0
I don't know ZeeBaine -15 — 3y
0
wdym? sne_123456 439 — 3y
0
tysm, but where do you put the script inside? 5402007 4 — 3y
0
just put it in workspace and make sure al the variables are right for you sne_123456 439 — 3y
View all comments (2 more)
0
thx 5402007 4 — 3y
0
np sne_123456 439 — 3y
Ad

Answer this question