Assigning multiple values to an attribute

I took a simple script and added a few changes for a guess the person system, so there is an alias for the person which is also marked as correct.

door = script.Parent
function onChatted(msg, recipient, speaker) 
	local source = string.lower(speaker.Name) 
	msg = string.lower(msg) 
	local char = script.Parent.TheCharacter
	local alias = char:GetAttribute("Alias")
	if msg == string.lower(char.Value) or msg == string.lower(alias) then 
		door.CanCollide = false 
		door.Transparency = 0.7 
		wait(4) 
		door.CanCollide = true 
		door.Transparency = 0 
	end 
end 
game.Players.ChildAdded:connect(function(plr)
	plr.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, plr) end) 
end)

image

this system works but I am trying to make multiple alias for the person using the same attribute. I tried using Lebron, James but it did not work.
image

Does anyone know if this is possible or do I just need to create multiple attributes?

1 Like

Unfortunately, properties and attributes don’t support tables.

However… you can convert the table to a string and vice versa, JSON for example. HttpService has 2 functions that allows you to convert a Lua table into JSON string and JSON string into a Lua table.

That’s just one of the ways, you can make your own system that converts a custom string into a table if you want.

1 Like

Just convert the alias attribute to a table using string.split() and , as the split operator.

door = script.Parent
function onChatted(msg, recipient, speaker) 
	local source = string.lower(speaker.Name) 
	msg = string.lower(msg) 
	local char = script.Parent.TheCharacter
	local aliases = string.split(char:GetAttribute("Alias"), ", ") -- using ', ' since that was what the attribute uses
	local function unlockDoor()
		door.CanCollide = false 
		door.Transparency = 0.7 
		wait(4) 
		door.CanCollide = true 
		door.Transparency = 0 
	end
	if msg == string.lower(char.Value) then 
		unlockDoor()
	else
		for i, alias in pairs(aliases) do
			if msg == string.lower(alias) then
				unlockDoor()
				break
			end
		end
	end 
end 
game.Players.ChildAdded:connect(function(plr)
	plr.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, plr) end) 
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.