Local Chat Door not working

I am trying to make a “chat door” (a door that opens when you say something in chat) that is only opened for the player who says the “code” in chat. But I keep running into problems that I can’t solve.

I’ve been trying to do this by making a local part and then putting a local script as the child of that part, which you can find that script below. Thing is, it doesn’t work, and I don’t even have a hint to why. I will try it, and it doesn’t work, and I look for errors in the output, but there are none. None of the prints come up, either.

Server script inside the local part (both are inside the Workspace)

local Parent = script.Parent

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		local lowercasemessage = string.lower(message)
		if lowercasemessage == "code" then
			print(player.Name.." has said the secret code!")
			Parent.CanCollide = false
			while Parent.Transparency < 1 do
				wait(0.01)
				Parent.Transparency = Parent.Transparency + 0.1
			end
			print("Transparency = 1 & CanCollide = false")
			wait(1)
			Parent.CanCollide = true
			while Parent.Transparency > 0 do
				wait(0.01)
				Parent.Transparency = Parent.Transparency - 0.1
			end
		end
	end)
end)

Oh, and if it’s important, here is the script that creates the local part (which is stored inside the StarterGui)

_G.LocalPart= Instance.new("Part")
game.Workspace.CodeScript.Parent = _G.LocalPart
_G.LocalPart.Name = "Code"
_G.LocalPart.Parent = game.Workspace
_G.LocalPart.Position = Vector3.new(-35.5, 0.5, -5)
_G.LocalPart.Size = Vector3.new(19, 1, 16)
_G.LocalPart.TopSurface = "Smooth"
_G.LocalPart.BottomSurface = "Smooth"
1 Like

Is the local script in Workspace? If so it won’t work because local scripts don’t run in Workspace.

Which one? Because the code one is in the Workspace - but I tried it as a server script too, and it doesn’t seem to fix anything.

That is probably because you are checking to see if the lowercase-converted message is “Code” but “Code” contains an uppercase letter so it is currently impossible for a player to type the command.

I changed the actual thing you have to say to “Code” because I don’t want people knowing the actual thing. By the way, the actual value is all lowercase.

Is your script which creates the local part a local or server script?

Local script‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

That could be the problem then, the server script is only being added in to the part on the client, so as far as the server is concerned, it isn’t there at all.

If you use a server script than it isn’t a local part, it’s just a part

local player = game.Players.LocalPlayer
local newPart = Instance.new("Part", workspace)
newPart.Name = "Code"
newPart.Position = Vector3.new(-35.5, 0.5, -5)
newPart.Size = Vector3.new(19, 1, 16)
newPart.TopSurface = "Smooth"
newPart.BottomSurface = "Smooth"

player.Chatted:Connect(function(message)
	local lowercasemessage = string.lower(message)
	if lowercasemessage == "code" then
		print(player.Name.." has said the secret code!")
		newPart.CanCollide = false
		while newPart.Transparency < 1 do
			wait(0.01)
			newPart.Transparency = newPart.Transparency + 0.1
		end
		print("Transparency = 1 & CanCollide = false")
		wait(1)
		newPart.CanCollide = true
		while newPart.Transparency > 0 do
			wait(0.01)
			newPart.Transparency = newPart.Transparency - 0.1
		end
	end
end)

Try putting this in your local script in StarterGui (or StarterPlayerScripts) and get rid of the server script in Workspace.

2 Likes

This won’t work because the script isn’t in Workspace.

After fixing your error though, it finally works. Thanks!

Oh my apologies, didn’t mean to write that line, glad you fixed it :slight_smile: