function touch(hit) p = game.Players:GetPlayerFromCharacter(hit.Parent) if p.Backpack.Key ~= nil then script.Parent.CanCollide = false wait() script.Parent.Transparency = .5 else print("Doesnt have key!") end end script.Parent.Touched:connect(touch)
When I touch the part with my key, it says:
Workspace.Part.Script:3: attempt to index global 'p' (a nil value)
here I have an idea for you to identify the character
function touch(hit) if not hit.Parent:IsA("Model") then Character = hit.Parent.Parent -- because it might be a tool or a hat else Character = hit.Parent -- then its a character because the character is a model else return nil -- if its neither end local p = game.Players:GetPlayerFromCharacter(Character) -- gets player from the variable Character if p.Backpack.Key ~= nil then script.Parent.CanCollide = false wait() script.Parent.Transparency = .5 else print("Doesnt have key!") end end script.Parent.Touched:connect(touch)
please vote up if this helped
Since the key you're touching is the part, the part's parent is the tool. Maybe redirect the part to the tool to the character itself (hit.Parent.Parent). Or follow what coltn5000 demonstrated.