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:
01 | local 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 ) |
key script:
01 | local tool = game.ReplicatedStorage.Key |
02 | local giver = script.Parent |
03 | local canGive = false |
04 |
05 | giver.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 |
16 | end ) |
there is a easy way to do this. this is ur script.
01 | local 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
01 | local 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. |
08 | keytool:Destroy() -- and as simple as that! |
09 | door.CanCollide = false |
10 | door.Transparency = 1 |
11 | end |
12 | end ) |