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

Help with Vip door?

Teaching a 9 y/o how to script and I am having trouble atm :P Seems right to me. I am making a door where only certain people can go through it. I can go through it no matter what though. It does not kill me either.

Admins = {"Player", "PreyStar"}


script.Parent.Touched:connect(function(hit)
	if hit.Parent.Name == (Admins[1]) or (Admins[2]) or (Admins[3]) or (Admins[4]) then
		script.Parent.CanCollide = false
		wait(1)
		script.Parent.CanCollide = true
		print (hit.Parent.Name)
	end
	
	if hit.Parent.Name ~= (Admins[1]) or (Admins[2]) or (Admins[3]) or (Admins[4]) then
		hit.Parent:BreakJoints()
	end
end)

1 answer

✓ Accepted answer

or separates two distinct conditions.

if condition1 or condition2

condition1 and condition2 are in no way related!

if hit.Parent.Name == (Admins[1]) or (Admins[2])

The left side of or and the right side of or aren't connected in any way, shape, or form!

And equivalent way to write your code would be

if hit.Parent.Name == (Admins[1]) or (Admins[2]) == true

Since strings are considered to be true by Lua, the condition will always pass.

All you need to do is write your conditions separately.

if hit.Parent.Name == (Admins[1]) or hit.Parent.Name == (Admins[2])

Although admittedly using dictionaries would make your code shorter.

3 comments

0

How could I write this in a dictionary form? Thanks for the help.

0

Look at the wiki link. It would be something like: admins = { ["Perci1"] = true } ... if admins[hit.Parent.Name]

0

The script is not working right. Even though my name is in the table, I am able to go through it but later kills me.

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