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

How do I make it where when I kill something a key drops and it opens a door?

Asked by 3 years ago

So I’m making a game where when you start a demon spawns and you have to kill it then when you kill it a key drops and you can use that key to open a door then move on. Does anybody have a clue on how I can do that?

0
Dude, this isn’t a request site. Why did so many people upvote this. Cynical_Innovation 595 — 3y

3 answers

Log in to vote
0
Answered by
RGRage 45
3 years ago

Working off what BRO_ITmeYO proposed, his code required a loop in order to check instances for the death of the demon which is not ideal. A better solution would be to use the function Died for the humanoid class and then destroy the demon so that there is no position conflicts. Also a clone of the original key would be useful in order to keep it for later uses such as other players joining the game.

-- Variables --
local demon = game:GetService("Workspace"):WaitForChild("Demon")
local key = game:GetService("ServerStorage"):FindFirstChild("Key")

if Demon:FindFirstChild("Humanoid") then
    local humanoid = Demon.Humanoid
    humanoid.Died:connect(function()
        local keySpawn = key:Clone()
        keySpawn.Parent = game.Workspace
        keySpawn.Position = demon.HumanoidRootPart.Position
        demon:Destroy()
    end)
end

I hope I helped and let me know if this works.

~RGRage

0
Yes is right. That was my bad. emervise 123 — 3y
Ad
Log in to vote
0
Answered by
emervise 123
3 years ago
local demon = game.Workspace.Demon
local key = game.ServerStorage.key

while wait(1)
    if demon.humanoid.health = 0 then
        key.Parent = game.Workspace
        key.Position = demon.HumanoidRootPart.Position + Vector3.new(0,1,0)

Log in to vote
0
Answered by
quinzt 201 Moderation Voter
3 years ago

previous post explained the key part, to make it open the door:

door.touched:Connect(function(key))
if key.Parent.Name == "Handle" and key.Parent.Parent.Name == "Key" then
door.cancollide = false
wait(3)
door.cancollide = true
end)

Answer this question