Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can this chat activated door script be used with a certain tool?

This is a chat activated door script that opens when you say a certain thing. I want to know if I'm able to make this only work if you're holding a certain tool. Is that possible.

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 == "alohomora") 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) 

1 answer

✓ Accepted answer

Here is an example of how to do it without the tool.

Enforcer = {} --USER ID

game.Players.PlayerAdded:Connect(function(plr)
	for _,i in pairs(Enforcer) do 
		if plr.UserId == i then --Checking if plr is an Enforcer
			plr.Chatted:Connect(function(doorCmnd) --Connecting Chat
				if string.lower(doorCmnd:sub(1, 9)) == 'alohomora' then --If you type in alohomora
					door.CanCollide = false --door.CanCollide = false
				end
			end)
		end
	end
end)

Doing it with the tool

Now there are many ways to activate the message only by equipping a tool. I like to do it the simple way which is by calling a Remote Event.

Local Script -

local tool = script.Parent -- Add tool here 
local onActive = game.ReplicatedStorage.onActive -- Remote Event - Activates tool

tool.Equipped:Connect(function()
	onActive:FireServer() -- Fires to ServerScript
end)

Server Script -

local door = workspace.Part
local onActive = game.ReplicatedStorage.onActive -- Remote Event

Enforcer = {} -- USER ID


onActive.OnServerEvent:Connect(function(plr)
	for _,i in pairs(Enforcer) do
		if plr.UserId == i then
			plr.Chatted:Connect(function(doorCmnd)
				if string.lower(doorCmnd:sub(1, 9)) == 'alohomora' then
					door.CanCollide = false
				end
			end)
		end
	end
end)

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