Still have questions? Join our Discord server and get real time help.
0

# Can someone explain me why this code is not working? Because I am desperate.

Edited 2 years ago

Hi guys. I would be really happy if you can explain me why this is not working.

this is the code:

local door = script.Parent

local vips = {"DNF2307","Roox4"} -- those are the arrays

local check = false

function checkVip(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
for i = 1, #vips do
if hit.Parent.Name == vips[i] then
check = true
elseif check == false then
humanoid.Health = 0
end
end
end

door.Touched:connect(checkVip)


So basically i made a vip door so only the people who have their name in the arrays are able to get through. The problem with this is that if someone who has their name in the arrays on the second place it will kill him. If on the first it's ok. And it also prints that the humanoid is a nil value which I don't understant too. If anyone of you know the solution please tell me. Thanks.

0
Why not set up a variable to show that it found the person as a VIP or not, and run lines 12-13 afterwards? TheeDeathCaster 2319 — 2y

-1

Fixed script:

local door = script.Parent

local vips = {"DNF2307","Roox4"} -- those are the arrays

function checkVip(hit)
if not hit.Parent:FindFirstChild("Humanoid") then return end
local humanoid = hit.Parent.Humanoid
for i = 1, #vips do
if hit.Parent.Name == vips[i] then return end
end
humanoid.Health = 0
end

door.Touched:connect(checkVip)

0
Thank you so much. God bless you. Roox4 6 — 2y
0
You are welcome :) tiraner300 903 — 2y