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

How do I make this script only work if it is spoken by specific teams?

Asked by 4 years ago

I would like this command to only work if it is spoken by a specific team member. Any help is much appreciated

Script--

local message = "[opencombatdoor]"
local door = script.Parent
function onChatted(msg, recipient, speaker)
    local source = string.lower(speaker.Name)
    msg = string.lower(msg)
    if (msg == message) then
        door.CanCollide = false
        for i = 1, 9 do
            door.Transparency = door.Transparency + 0.1
            wait()
        end
        wait(10)
        for i = 1, 9 do
            door.Transparency = door.Transparency - 0.1
            wait()
        end
        door.CanCollide = true
    end
end

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

game.Players.PlayerAdded:connect(onPlayerEntered)

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You would most likely be looking for a conditional debounce at the top of your function. This statement is using the .Team property of Player, which is viewed as speaker through the argument given by the Chatted signal. All that information should be used like so:

function onChatted(msg, recipient, speaker)
   if (speaker.Team ~= "Insert Team name here") then return end
end

It is also advised that you use Connect instead.

0
If this works please remember to accept this answer Ziffixture 6913 — 4y
Ad

Answer this question