hello again, I have a model of a key in my map, if you press on it, then the key (tool) appears in my backpack; if I touch the door with this key, the door opens. I want to make sure that after the door is opened, the key deletes from my backpack. I tried to do it by myself and find info about this on the internet but did not find it. I would be very grateful if someone knows how to do this. sorry if I'm asking too much
door script:
local door = script.Parent.Door
local keystatus = false
door.Touched:Connect(function(hit)
local itskey = hit.Parent.Key
if itskey then
door.CanCollide = false
door.Transparency = 1
end
end)
key script:
local tool = game.ReplicatedStorage.Key
local giver = script.Parent
local canGive = false
giver.ClickDetector.MouseClick:Connect(function(player)
if canGive == false then
canGive = true
local clone = tool:Clone()
clone.Parent = player.Backpack
wait()
canGive = false
game.Workspace.KeyGiver:Destroy()
end
end)

1 comment
thank you