Still have questions? Join our Discord server and get real time help.
0

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

RareBIue 133
2 months 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. 14zanderbilt 527 — 2mo

0
RGRage 45
2 months 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. BRO_ITmeYO 106 — 2mo
0
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)


0
quinzt 201
2 months 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)