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.
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)