So I'm trying to make a horror game and I have a door system but I want the key to disappear after use (the key also doesn't appear in the backpack it appears under players and then the playername)
KeyCode:
local tool = script.Parent.Parent
local click = script.Parent.ClickDetector
local function pickup(player)
tool.Parent = game.Workspace[player.Name]
end
DoorCode:
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "Key" then
script.Parent.CanCollide = false
script.Parent.Transparency = 1
script.Parent.Parent.DoorOpen.CanCollide = true
script.Parent.Parent.DoorOpen.Transparency = 0
local sound = game.Workspace.Door.DoorClose.DoorScript.doorsound
local part = script.Parent
local function music()
if not sound.IsPlaying then
sound:Play()
end
end
part.Touched:Connect(music)
wait(1)
script.Parent.CanCollide = true
script.Parent.Transparency = 0
script.Parent.Parent.DoorOpen.CanCollide = false
script.Parent.Parent.DoorOpen.Transparency = 1
end
end)
I had something in mind like this :
game.Workspace[player.Name]:FindFirstChild("Key"):Destroy()
but it wouldn't work because I don't have the players name If I put my name it works fine.

1 comment
Try Hit.Parent.Parent.Name to get the player's name