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

How do I implement the door's name into the script?

So I'm making a quiz I was wondering how I could make it so that when I say the door's name it would open instead of going into the script to edit the message every time. Here's the script:

door = script.Parent --this is the door 

function onChatted(msg, recipient, speaker) 

-- convert to all lower case 

local source = string.lower(speaker.Name) 
msg = string.lower(msg) 

if (msg == "hi") then 
door.CanCollide = false 
door.Transparency = 0.7
wait(5) 
door.CanCollide = true 
door.Transparency = 0 
end 

end 

function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered) 

I tried using door.Name instead of "hi" but it didn't work. Help? Thanks.

2 comments

0

If the door's name has a capital letter, then you'll want to make the name lowercase in the script when comparing strings, since you have msg in all lowercase letters. Otherwise, I don't see your problem.

0

Show how you'd add door.Name to your script.

1 answer

✓ Accepted answer

First, let me answer the question you posed:

To access the Name property of the door, simple use door.Name where you want to get it.

In this case, replace line 10:

if (msg == "hi") then

with:

if (msg == string.lower(door.Name)) then

However....


Your method is a very bad way to go about making quiz-doors if you're using that exact same Script for each and every door. It's a lot more efficient to use a single script:

local Doors = workspace.Doors --This is a Model containing all the Quiz Door parts.
local debounces = {}

game.Players.PlayerAdded:connect(function(plr)
	plr.Chatter:connect(function(m, recip)
		m = string.lower(m)

		for _, door in ipairs(Doors:GetChildren()) do
			if not debounces[door] and m == string.lower(door.Name) then
				debounces[door] = true
				door.Transparency = 0.7
				door.CanCollide = false
				wait(5)
				debounces[door] = false
				door.Transparency = 0
				door.CanCollide = true
			end 
		end
	end)
end)

2 comments

0

This does help...but how do I use this script?

0

Instead of having a script inside each quiz door listening to every Players' Chatted event, put all the Door parts into a Model in the Workspace called "Doors", as the first line of my script indicates, and then just use this one script.

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