Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do i make a key that will destroy after i open door?

Asked by 3 years ago

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 answer

Log in to vote
0
Answered by 3 years ago

there is a easy way to do this. this is ur 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)

now to fix it would need some changes i will show

local door = script.Parent.Door
    local keystatus = false
    door.Touched:Connect(function(hit)

    local itskey = hit.Parent.Key
        if itskey then
            local keytool = hit.Parent.Key.Parent -- im assuming the key is the child of the actual tool.so basically do this.
keytool:Destroy() -- and as simple as that!
            door.CanCollide = false
            door.Transparency = 1
        end
        end)
0
thank you OleshaDumayet 9 — 3y
Ad

Answer this question