Gate command who do not work

Hello,

I wanted to create a moving door with TweenService, only people with a certain minimum rankID in a certain group can use this command, to open or close the door

The issue is that the door work with a simple click detector, but won’t work with a command.

I tried many things, but nothing worked, that’s why I ask for some help.

local open = false
local GroupID = 5043968
local HR = 24 
local Plr = game:GetService("Players")

local door1 = script.Parent

local TweenService = game:GetService("TweenService")

 

local tweenInfo = TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

 

local Door1Open = {CFrame = door1.CFrame + door1.CFrame.lookVector * 35}
local Door1Close = {CFrame = door1.CFrame }



local Open1 = TweenService:Create(door1,tweenInfo,Door1Open)
local Close1 = TweenService:Create(door1,tweenInfo,Door1Close)

Plr.Chatted:connect(function(msg)
	if Plr:GetRankInGroup(GroupID) >= HR then
		if open == false and msg == "!gate open" then
			Open1:play()
			print("Gate Opened")
			open = true
		elseif
			open == true and msg == "!gate close" then
				Close1:play()
				print("Gate Closed")
				open = false
		end
	end
end)
 

If I look into the DevHub API reference about Players service, it has no .Chatted event, maybe try .PlayerChatted instead.

Possibly try replacing “open” with some other variable? It seems to be highlighted as syntax and might be interfering.

You defined Plr as the Players Service. You will need to provide the name or the player sending the message from the Players.PlayerChatted event.

@Dev_Kittenz I got an error when I tried to replace Chatted by PlayerChatted, still not working.

@RudraVII Still not Working

@xZylter I tried without Plr as the Player Service Group and without the Rank requirement, and with using PlayerChatted and still not working, I got this error:

.PlayerChatted only works in the command bar.

1 Like

This will work you just need to add an extra connection for when the player joins using PlayerAdded.

--Script from Roblox Developer Website
game.Players.PlayerAdded:Connect(function(player)
  player.Chatted:Connect(function(msg)
        -- do stuff with msg and player
  end)
end)

No, you’re wrong. There’s a Player.Chatted event. Nice attempt, though, but please be careful if you’re not even sure what you’re talking about.

1 Like

You didn’t define who those players are, you need to be specific. Try using the PlayerAdded event, like so.

local open = false
local GroupID = 5043968
local HR = 24 
local door1 = script.Parent

local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

local Door1Open = {CFrame = door1.CFrame + door1.CFrame.lookVector * 35}
local Door1Close = {CFrame = door1.CFrame }

local Open1 = TweenService:Create(door1,tweenInfo,Door1Open)
local Close1 = TweenService:Create(door1,tweenInfo,Door1Close)


game.Players.PlayerAdded:Connect(function(Plr)
Plr.Chatted:Connect(function(msg)
	if Plr:GetRankInGroup(GroupID) >= HR then
		if open == false and msg == "!gate open" then
			Open1:play()
			print("Gate Opened")
			open = true
		elseif
			open == true and msg == "!gate close" then
				Close1:play()
				print("Gate Closed")
				open = false
		end
	end
end)
end)
 

I already mentioned this in a previous reply.

Thanks @xZylter and @slothfulGuy now it work perfectly, thanks for your help c: .

They aren’t wrong, they just got confused as to which was the proper event to be using. PlayerChatted and Chatted are two different events: one is used internally and one is exposed to the developer for their own use. Chatted is not a member of Players but it is of the Player object and vice versa for PlayerChatted.