Client side word door

Hello!

I am trying to adapt my server side word door to a client side and it does not work, I am a new scripter so I do not know why.

local door = game.Workspace:WaitForChild("RAWR")
local keyword = "hi" 

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if string.lower(message) == keyword then
			door.Transparency = 1
			door.CanCollide = false
			wait(10) 
			door.Transparency = 0
		else
			door.CanCollide = false
		end
	end)
end)

This is my code, it is in StarterPlayerScripts as a LocalScript.
Thank you!

2 Likes

You’re setting CanCollide to false but not true afterwards. You’ll need to do this to fix that problem (I also added a debounce, and it will need to be a LocalScript inside StarterPlayerScripts for this to work):

local door = game.Workspace:WaitForChild("RAWR")
local keyword = "hi" 

local player = game.Players.LocalPlayer

local debounce

player.Chatted:Connect(function(message)
	if string.lower(message) == keyword and not debounce then
		debounce = true
		door.Transparency = 1
		door.CanCollide = false
		task.wait(10)
		door.CanCollide = true 
		door.Transparency = 0
		debounce = nil
	end
end)

Hello, thank you for your help! I have copy and pasted exactly what you have coded/changed however and it still does not work.

There is no error message but it does not run regardless. (It is a LocalScript within StarterPlayerScripts)

Are you using LegacyChat or TextChatService?

1 Like

TextChatService,

and I don’t know if this means anything but the script DID work before I changed it into a local script

Oh I switched it to Legacy and it worked! Thank you very much!

1 Like

This should work now with TextChatService if you prefer it over legacy, I tested it and it works correctly on my end:

local door = game.Workspace:WaitForChild("RAWR")
local keyword = "hi" 

local player = game.Players.LocalPlayer

local debounce

game.TextChatService.OnIncomingMessage = function(message)
	if message.Status == Enum.TextChatMessageStatus.Success then
		if message.TextSource and message.TextSource.UserId == player.UserId then
			if string.lower(message.Text) == keyword and not debounce then
				debounce = true
				door.Transparency = 1
				door.CanCollide = false
				task.wait(10)
				door.CanCollide = true 
				door.Transparency = 0
				debounce = nil
			end
		end
	end
end
2 Likes

Thanks for the help - I have another question;

when I change the scripts keyword to something like “Open” it stops working. Is there a reason for this? I fail to understand why it works with “hi” and not something like “Open”.

Also, does the “string.lower” mean that whatever the keyword is I have to type it out in lower case in order for it to work? Sorry for all the questions, I have never dealt with player message based codes before.

The keyword needs to be written in all lowercase characters, so “Open” will need to be “open”

string.lower will automatically convert all the characters in the message to lowercase versions, so even if you chat “OPEN” the door will still turn invisible and non-collidable

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