I made these scripts to check if the value in the key matches, but the script works only for the query of the name and not the value. Could you help me, please?
local door = script.Parent.Door
local door2 = script.Parent.Door2
local hinge = script.Parent.Door.Hinge
local hinge2 = script.Parent.Door2.Hinge
local hingePos = hinge.Position
local hingePos2 = hinge2.Position
local open = false
local cooldown = false
script.Parent.Scanner1.Toch.Touched:Connect(function(hit)
if hit.Parent.Level.Value == "5" then
if open == false and cooldown == false then
cooldown = true
script.Parent.Scanner1.Lights.green2.Material = "Neon"
for i = 1, 18, 1 do
door:SetPrimaryPartCFrame(door:GetPrimaryPartCFrame(hingePos) * CFrame.new(0,0.2,0))
door2:SetPrimaryPartCFrame(door2:GetPrimaryPartCFrame(hingePos2) * CFrame.new(0,-0.2,0))
wait()
end
script.Parent.Scanner1.Lights.green2.Material = "Metal"
cooldown = false
open = true
elseif open == true and cooldown == false then
cooldown = true
script.Parent.Scanner1.Lights.green2.Material = "Neon"
for i = 1, 18, 1 do
door:SetPrimaryPartCFrame(door:GetPrimaryPartCFrame(hingePos) * CFrame.new(0,-0.2,0))
door2:SetPrimaryPartCFrame(door2:GetPrimaryPartCFrame(hingePos2) * CFrame.new(0,0.2,0))
wait()
end
script.Parent.Scanner1.Lights.green2.Material = "Metal"
wait(1)
cooldown = false
open = false
end
end
end)
Thank you for posting what you are trying to do in the post, but more details would also be helpful in the future. I’d suggest sharing a place/model file, or sharing errors that show up in the output window.
From the code given, I would suggest checking to see if “Level” exists before trying to operate on it.
local door = script.Parent.Door
local door2 = script.Parent.Door2
local hinge = script.Parent.Door.Hinge
local hinge2 = script.Parent.Door2.Hinge
local hingePos = hinge.Position
local hingePos2 = hinge2.Position
local open = false
local cooldown = false
script.Parent.Scanner1.Toch.Touched:Connect(function(hit)
local levelTag = hit.Parent:FindFirstChild('Level')
if levelTag and levelTag.Value == "5" and cooldown == false then
cooldown = true
if open == false then
script.Parent.Scanner1.Lights.green2.Material = "Neon"
for i = 1, 18, 1 do
door:SetPrimaryPartCFrame(door:GetPrimaryPartCFrame(hingePos) * CFrame.new(0,0.2,0))
door2:SetPrimaryPartCFrame(door2:GetPrimaryPartCFrame(hingePos2) * CFrame.new(0,-0.2,0))
wait()
end
script.Parent.Scanner1.Lights.green2.Material = "Metal"
open = true
elseif open == true then
script.Parent.Scanner1.Lights.green2.Material = "Neon"
for i = 1, 18, 1 do
door:SetPrimaryPartCFrame(door:GetPrimaryPartCFrame(hingePos) * CFrame.new(0,-0.2,0))
door2:SetPrimaryPartCFrame(door2:GetPrimaryPartCFrame(hingePos2) * CFrame.new(0,0.2,0))
wait()
end
script.Parent.Scanner1.Lights.green2.Material = "Metal"
wait(1)
open = false
end
cooldown = false
end
end)