Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Roox4 21
6 years ago
Edited 6 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 2368 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

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 21 — 6y
0
You are welcome :) Le_Teapots 913 — 6y
Ad

Answer this question