so what i mean by that is im checking to see if something exists, and if it doesnt text says its locked. but the text cant show up because it errors saying the Value doesnt exists when it isnt supposed to, is there a better way to check?
local key1 = workspace.Key1 script.Parent.ClickDetector.MouseClick:connect(function(click) local moving = false if moving == false then moving = true if click.Backpack.Key1 then key1.Sound:Play() key1.Sound:Destroy() key1.ClickDetector:Destroy() game.Players.LocalPlayer.Backpack.Key1:Destroy() local num = 0 repeat num = num + 1 key1.CFrame = key1.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0) wait(0.01) until num > 17 end else script.Parent.Text = "Hmm... Its locked..." script.Parent.Visible = true for i= 1,10 do wait() script.Parent.TextTransparency = 1-(i*0.1) end wait(2) for i= 1,10 do wait() script.Parent.TextTransparency = (i*0.1) end end end)
Error: > 22:30:45.418 - Key1 is not a valid member of Backpack
On line 7, instead of:
if click.Backpack.Key1 then
Make it:
if click.Backpack:findFirstChild("Key1") then
Final Script
local key1 = workspace.Key1 script.Parent.ClickDetector.MouseClick:connect(function(click) local clicker = click -- storing the player that clicked local moving = false if moving == false then moving = true if clicker.Backpack:findFirstChild("Key") then print("working") key1.Sound:Play() key1.Sound:Destroy() key1.ClickDetector:Destroy() clicker.Backpack.Key1:Destroy() local num = 0 repeat num = num + 1 key1.CFrame = key1.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0) wait(0.01) until num > 17 end else script.Parent.Text = "Hmm... Its locked..." script.Parent.Visible = true for i= 1,10 do wait() script.Parent.TextTransparency = 1-(i*0.1) end end wait(2) for i= 1,10 do wait() script.Parent.TextTransparency = (i*0.1) end end)
I tested it and it worked perfectly fine for me. So you might be doing something wrong.
Hope this helps!
The problem here is that if Key1 doesn't exist, asking the script to look for Key1 will be impossible! There's a simple way to fix this.
if click.Backpack:FindFirstChild("Key1") ~= nil then
FindFirstChild looks for the child with the name in quotations. If it doesn't exist, it returns nil. So if it doesn't return nil, the script continues!