Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Removing things out of players inventory?

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

0

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

1 answer

ok use this code i changed ur code:

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)

	local character = hit.Parent.Parent -- this line gives the character from the touched hit(KEY)
	character:FindFirstChild("Key"):Destroy() -- this line destroy the key

        script.Parent.CanCollide = true
        script.Parent.Transparency = 0
        script.Parent.Parent.DoorOpen.CanCollide = false
        script.Parent.Parent.DoorOpen.Transparency = 1

    end
end)

1 comment

0

i hope it help u

This discussion is preserved as it was. New answers, comments, and votes are closed.