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?
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
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)
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)