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 make this script only work if it is spoken by specific teams?

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

✓ Accepted answer

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.

1 comment

0

If this works please remember to accept this answer

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