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:

01local door = script.Parent.Door
02local keystatus = false
03door.Touched:Connect(function(hit)
04 
05local itskey = hit.Parent.Key
06    if itskey then
07        door.CanCollide = false
08        door.Transparency = 1
09    end
10    end)

key script:

01local tool = game.ReplicatedStorage.Key
02    local giver = script.Parent
03    local canGive = false
04 
05giver.ClickDetector.MouseClick:Connect(function(player)
06    if canGive == false then
07        canGive = true
08        local clone = tool:Clone()
09        clone.Parent = player.Backpack
10        wait()
11        canGive = false
12        game.Workspace.KeyGiver:Destroy()
13 
14    end
15 
16end)

1 answer

Log in to vote
0
Answered by 3 years ago

there is a easy way to do this. this is ur script.

01local door = script.Parent.Door
02    local keystatus = false
03    door.Touched:Connect(function(hit)
04 
05    local itskey = hit.Parent.Key
06        if itskey then
07            door.CanCollide = false
08            door.Transparency = 1
09        end
10        end)

now to fix it would need some changes i will show

01local door = script.Parent.Door
02    local keystatus = false
03    door.Touched:Connect(function(hit)
04 
05    local itskey = hit.Parent.Key
06        if itskey then
07            local keytool = hit.Parent.Key.Parent -- im assuming the key is the child of the actual tool.so basically do this.
08keytool:Destroy() -- and as simple as that!
09            door.CanCollide = false
10            door.Transparency = 1
11        end
12        end)
0
thank you OleshaDumayet 9 — 3y
Ad

Answer this question