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 4 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 — 4y

3 answers

Log in to vote
0
Answered by
RGRage 45
4 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.

01-- Variables --
02local demon = game:GetService("Workspace"):WaitForChild("Demon")
03local key = game:GetService("ServerStorage"):FindFirstChild("Key")
04 
05if Demon:FindFirstChild("Humanoid") then
06    local humanoid = Demon.Humanoid
07    humanoid.Died:connect(function()
08        local keySpawn = key:Clone()
09        keySpawn.Parent = game.Workspace
10        keySpawn.Position = demon.HumanoidRootPart.Position
11        demon:Destroy()
12    end)
13end

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

~RGRage

0
Yes is right. That was my bad. emervise 123 — 4y
Ad
Log in to vote
0
Answered by
emervise 123
4 years ago
1local demon = game.Workspace.Demon
2local key = game.ServerStorage.key
3 
4while wait(1)
5    if demon.humanoid.health = 0 then
6        key.Parent = game.Workspace
7        key.Position = demon.HumanoidRootPart.Position + Vector3.new(0,1,0)
Log in to vote
0
Answered by
quinzt 201 Moderation Voter
4 years ago

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

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

Answer this question