Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

1 comment

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?

1 answer

✓ Accepted answer

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)

2 comments

0

Thank you so much. God bless you.

0

You are welcome :)

This discussion is preserved as it was. New answers, comments, and votes are closed.