Hello, I tried to make a keycard door, it would work when you hit it with a keycard, that keycard has a level IntValue inside of it, if the IntValue is lower than e.g 2 then it wont open.
My problem here is “attempt to index nil with ‘Value - Server - Script:20’”
When the keycard hits it should look for that Intvalue, but for some reason its nil
Also i get the error " Unable to cast to Dictionary - Server - Script:24"
this is the script:
--//Service
local tweenService = game:GetService("TweenService")
--//Settings
local door = script.Parent.Door:WaitForChild("Door")
local reader = script.Parent.KCReader:WaitForChild("Reader")
local open = false
local debounce = false
--//Script
reader.Touched:connect(function(hit)
local keycard = hit.Parent:FindFirstChild("Level")
local doorOperation = TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0 , false, 0)
if keycard.Value >= 0 and debounce == false then
if open == false then
debounce = true
local openDoor = {CFrame = 0, -2, 0}
local open = tweenService:Create(door, doorOperation, openDoor)
open:Play()
wait(2)
debounce = false
elseif open == true then
debounce = true
local closeDoor = {CFrame = 0, 2, 0}
local close = tweenService:Create(door, doorOperation, closeDoor)
close:Play()
wait(2)
debounce = false
end
end
end)
Could you send a screenshot of the keycard in game explorer? The most likely issue I can think of at the moment is if Level is inside the Handle of the keycard not the tool in which case hit.Parent needs to be changed to hit:FindFirstChild(‘Level’)
When the reader is touched you need to make sure that it is a player or the keycard that touched it
reader.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Level") then --makes sure that there is a level
local keycard = hit.Parent:FindFirstChild("Level")
local doorOperation = TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0 , false, 0)
if keycard.Value >= 0 and debounce == false then
if open == false then
debounce = true
local openDoor = {CFrame = 0, -2, 0}
local open = tweenService:Create(door, doorOperation, openDoor)
open:Play()
wait(2)
debounce = false
elseif open == true then
debounce = true
local closeDoor = {CFrame = 0, 2, 0}
local close = tweenService:Create(door, doorOperation, closeDoor)
close:Play()
wait(2)
debounce = false
end
end
end --end of the if statement
end)