I've made a detector script which sees if a player has a tool in their backpack called "LavaKey" and then if so opens a door by making it invisible and then waits 8 seconds and closes it. The issue is I cant seem to get the line that sees if the key is in the backpack correct and when I run the game and step on the detector I get an error on line 10 saying that "Backpack is not a valid member of Model" but then after that I get no more errors. (That error may be referring to the door thats on the detector or something but it doesnt have a humanoid. Anyone know what I need to fix? Thx.
local detector = script.Parent
local door = game.Workspace.LavaDoor
DB = true
detector.Touched:Connect(function(hit)
if DB == true then
DB = false
if hit.Parent:FindFirstChild('Humanoid') then
local hum = hit.Parent:FindFirstChild('Humanoid')
if hit.Parent.Backpack:FindFirstChild("LavaKey") then--here
door.Transparency = 1
door.CanCollide = false
wait(8)
door.Transparency = 0
door.CanCollide = true
elseif not hit.Parent.Backpack:FindFirstChild("LavaKey") then
hum:TakeDamage(20)
end
wait(2)
DB = true
end
end
end)

1 comment
i ended up fixing it by using, "local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)"