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)
@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:
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)
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)
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.