So, I have an if statement that checks if the player has a key, and if the player doesn't have it, it plays a sound. But I have the key and the door doesn't open. The script is also a local script.
01 | game.Players.LocalPlayer.CharacterAdded:Wait() |
02 | local Door = workspace.Door.MyBigPPpart |
03 | local d = false |
04 | local TweenService = game:GetService( "TweenService" ) |
05 |
06 | Door.ProximityPrompt.Triggered:Connect( function (player) |
07 | if not d then |
08 | d = true |
09 | local anim = player.Character.Humanoid:LoadAnimation(script.Pickup) |
10 | anim:Play() |
11 | if not player.Backpack:FindFirstChild( "Door1Key" ) or not player.Character:FindFirstChild( "Door1Key" ) then |
12 | Door.Lock:Play() |
13 | elseif player.Backpack:FindFirstChild( "Door1Key" ) or player.Character:FindFirstChild( "Door1Key" ) then |
14 | local info = TweenInfo.new( |
15 | 1 , |
If you want to check if the player doesn't have the key, you should be checking his Backpack and his Character, and not just his Backpack or his Character. If you use or
, it will also be true since he can only have it at one place at once, even if he does have the key.
Basically: Replace or
with and
in the first if-statement (the one that checks if the player does not have the key).