I have a script that I got from a free model. I've been working with it for a while now to add a lot more uses to it, but it seems that the original code, and therefore this code, breaks whenever someone dies. This script in particular uses multiple things I'm unfamiliar with, so I have genuinely no clue how to fix this.
while true do
for n,k in pairs(game.Players:GetChildren()) do
if (script.Parent.Position - k.Character.Torso.Position).magnitude < distance then
check = check + 1
end
end
if check >= 1 then
if open == false then
open = true
for i = 0,width*2 do
//(stuff)
wait(0.05)
end
end
else if check == 0 then
if open == true then
open = false
for i = 0,width*2 do
//(more stuff)
end
end
end
end
check = 0
wait()
end

3 comments
check if k is nil
check if k is nil
@Goulstem: surely k will never be nil? If it was, it wouldn't be returned by 'pairs'