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

Local script if statement doesn't work?

Asked by 2 years ago

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.

01game.Players.LocalPlayer.CharacterAdded:Wait()
02local Door = workspace.Door.MyBigPPpart
03local d = false
04local TweenService = game:GetService("TweenService")
05 
06Door.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,
View all 52 lines...

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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).

Ad

Answer this question