Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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.

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. M39a9am3R 3210 — 9y
0
Show how you'd add door.Name to your script. funyun 958 — 9y

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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)
0
This does help...but how do I use this script? VentusWind78 25 — 8y
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. adark 5487 — 8y
Ad

Answer this question