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

Can someone help me?

Okay well I'm trying to create a door that opens to my command but it doesn't work. I can't seem to figure out what wrong but I'm guessing most of it is incorrect. ~~~~~~~~~~~~~~~~~



Door=script.Parent


admin = {"mkjp87"}

function open()
	Door.CanCollide=false
	Door.Transparency=1
end

game.Players.PlayerAdded:connect(function(nP)
for _,v in pairs (admin) do
if nP.Name == v then
nP.Chatted:connect(function(msg)
	if msg == "Holo Open" then
	connect(open)
end

1 comment

1

mkjp87, your script has to go in between the "~~~" lines.

3 answers

Alright, first of all, put a wait in the function... I suggest something like wait(1), just within the function block, then, you may want to convert the message to String.lower. I put some code below to give examples of both. Of course if you chat "Holo Open" exactly with capitalization it you won't need String.lower. Also, connect(open) won't work... you need an event and a colon before putting connect. open() should work fine for calling the function.

--not the full function here
nP.Chatted:connect(function(msg)
lowermsg = String.lower(msg)
if lowermsg == "holo open" then
open()
end

----------
--full function
function open()
Door.CanCollide=false
Door.Transparency=1
wait(1) -- door will stay open for 1 second, use teleportation if you want to safeguard door from those who may get in when the owner goes in in that 1 sec time frame
end
Door.CanCollide = true
Door.Transparency = 0
--reset door if you want

3 comments

0

wait(1) won't accomplish anything in this case... You don't do anything after. He didn't specify that he wants it to close immediately after, anyway.

0

the door won't be open for very long if you dont add a wait... and you repeated some of the things I already fixed in their script...

0

A function terminates after the one second wait mark. The script will not run lines 15 and 16, simply because it is not in the function.

There's no such thing as connect -- ScriptAnalysis should warn you about that.

If you want the door to open, just call open().


You also need appropriate ends to match the if, for, and two function blocks you started (and also two closing parenthesis).


It's good practice to put space around symbols, Transparency = 1 instead of Transparency=1, _, v instead of _,v: it makes it much easier to read.


I would also suggest moving the chatted function out of the loop -- it's usually better to avoid stacking things more than a few levels deep.

function adminSaid(msg, who)
	if msg == "Holo Open" then
		open()
	end
end

game.Players.PlayerAdded:connect(function(nP)
	for _, v in pairs(admin) do
		if nP.Name == v then
			nP.Chatted:connect(function(msg)
				adminSaid(msg, nP)
			end)
		end
	end
end)

This'll make it a little cleaner to add more commands, too, since you won't be editing the body of a connection in an if in a for in a connection.

Your problem is that you're trying to check if they're on the admin list before you define the Chatted Event. The Event fires no matter what, you can't say 'if [condition] then [event]'

Also, you have to call the function by doing; open() .

So, to fix?

local Door = script.Parent
local admins = {"mkjp87","Goulstem"}

function open() 
	Door.CanCollide = false 
	Door.Transparency = 1 
end

game.Players.PlayerAdded:connect(function(nP) 
	nP.Chatted:connect(function(msg) 
		for i,v in pairs(admins) do
			if nP.Name == v then
				if msg:lower() == "holo open" then --So it's not case sensitive
					open()
				end
			end
		end
	end)
end)

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