Need help with scripting a code combination door

I need help with making something like when a user chats a code the block will disappear specifically just for the user who chatted the code.

Please send link to new model or script


Model: Door - Roblox


Script:

door = script.Parent
function onChatted(msg, recipient, speaker) 
source = string.lower(speaker.Name) 
msg = string.lower(msg) 
thecharacter = script.Parent.TheCharacter
if (msg == string.lower(thecharacter.Value)) then 
door.CanCollide = false 
door.Transparency = 1 
wait(3) 
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)

Game Link: Door Testing Place - Roblox (Say in chat: 8)

First, add a remote event into ReplicatedStorage:
image

Second, add a local script into StarterPlayerScripts and paste this into it.

Location:
image

Script:

--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local RemoteEvent = ReplicatedStorage.RemoteEvent
local Door = workspace.Door --//Reference your door

--//Functions
RemoteEvent.OnClientEvent:Connect(function()
	--//Make door invisible
	Door.CanCollide = false 
	Door.Transparency = 1 
end)

Lastly, add a server script into ServerScriptService and paste this into it:

Location:
image

Script:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local Code = "MyCode"
local RemoteEvent = ReplicatedStorage.RemoteEvent

--//Functions
Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(text)
		if text == Code then
			RemoteEvent:FireClient(player)
		end
	end)
end)

It should work now. Change the code variable and door variable to match your situation.

Video of it working:

1 Like

The problem i run into is I want to add mutiple code doors

Change the server script to this:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local RemoteEvent = ReplicatedStorage.RemoteEvent

--//Tables
local Codes = { --//Reference your codes here
	"MyFirstCode",
	"MySecondCode",
}

--//Functions
Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(text)
		if table.find(Codes, text) then
			RemoteEvent:FireClient(player, text)
		end
	end)
end)

And the local script to this:

--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local RemoteEvent = ReplicatedStorage.RemoteEvent

--//Doors
local Door1 = workspace.Door1 --//Reference your door
local Door2 = workspace.Door2 --//Reference your door

--//Functions
RemoteEvent.OnClientEvent:Connect(function(text)
	if text == "MyFirstCode" then
		Door1.CanCollide = false 
		Door1.Transparency = 1 
	elseif text == "MySecondCode" then
		Door2.CanCollide = false 
		Door2.Transparency = 1 
	end
end)
1 Like