plr.Parent would be referring to the Hit’s Parent every time the Touched function is called, I’d check first if RedKey isn’t equal to nil before you check for the Value of it
Also, I’d recommend implementing a debounce first cause that event will fire every time it gets touched by something, and will overlap other Hit parts as well
local Part = script.Parent.Parent
local DB = false
script.Parent.Touched:Connect(function(Hit)
if DB then return end
local Char = Hit.Parent
if Char then
local RedKey = Char:FindFirstChild("BlockKey")
if RedKey and RedKey.Value == "1" then
DB = true
script.Parent.Script.Disabled = true
script.Parent.Door.Transparency = 0
script.Parent.Door.CanCollide = true
wait(.1)
script.Parent.Script.Disabled = false
script.Parent.Door.Transparency = 0.35
script.Parent.Door.CanCollide = false
DB = false
end
end
end)
Your touched event only checks if the touchedpart has a BlockKey but you aren’t detecting if the touchedpart is actually a player. Try this:
local part = script.Parent.Parent
script.Parent.Touched:Connect(function(plr)
local char = plr.Parent
print(char)
if game.Players:FindFirstChild(char.Name) then
local GrabBlock = char:FindFirstChild("GrabBlock")
if GrabBlock then
local RedKey = GrabBlock:WaitForChild("BlockKey")
if RedKey.Value == "1" then
script.Parent.Script.Disabled = true
script.Parent.Door.Transparency = 0
script.Parent.Door.CanCollide = true
wait(0.1)
script.Parent.Door.Transparency = 0.35
script.Parent.Door.CanCollide = false
script.Parent.Script.Disabled = false
end
end
end
end)
What you’re saying is that, Char is actually referring to the Part’s Parent of that Block? That’s the reason why it keeps returning back as nil, because there’s no proper properties to look for if you’re just looking for the part alone inside of Part.Parent, you can just simply do Part
It kinda confused us where you even got the Char variable even from Just a reminder that Hit refers to the BasePart it touched, and Hit.Parent is the BasePart’s Parent (Not the actual Block inside the StringValue), cause you would be referring to the HitPart (Left Arm, Right Leg, Torso)'s Parent which is the Character Model
@jumpyfunk That’s what I was assuming, but we weren’t really sure on the whole incident