Trying to make a door open and close thingy with the Chatted function

I was trying to make a door that can be open/closed. Whenever someone says “open” it will;
Set the transparency to 1, causing it to “dissapear”. And CanCollide setting to false.
Same for “close” but transparency and cancollide is vise versa.

Code:

local whitelist = "TheGuy_IAm"
local player = game.Players.LocalPlayer
local part = script.Parent

part.Anchored = true

game.Players.PlayerAdded:Connect(function(player,whitelist,part)
	player.Chatted:Connect(function(msg)
		if string.lower(msg) == "open" and player.Name == whitelist then
			part.Transparency = 1
			part.CanCollide = false
		elseif string.lower(msg) == "close" and player.Name == whitelist then
			part.Transparency = 0
			part.CanCollide = true
		end
	end)
end)

Please only respond if you have experience in scripting.

Change your code to this.

local whitelist = "TheGuy_IAm"
local part = script.Parent

part.Anchored = true

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if string.lower(msg) == "open" and player.Name == whitelist then
			part.Transparency = 1
			part.CanCollide = false
		elseif string.lower(msg) == "close" and player.Name == whitelist then
			part.Transparency = 0
			part.CanCollide = true
		end
	end)
end)
1 Like