So I have this in a server script. I want to be where they type :open in the chat, it opens this part named “Door.” Except they have to be above the group rank 10.
It doesn’t work, but has no errors? I just started learning lua so there’s probably something I did wrong. I accidentally hit enter but forgot to add something. Give me a second to fix the script.
local Players = game:GetService("Players")
local GROUP_ID = 5560221
if Player:GetRankInGroup(<10) then
onChatted(msg, speaker)
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == ":open" then
local door = workspace:FindFirstChild("Door")
local function open()
door.CanCollide = true
door.Transparency = 1
end
end
end)```
local function open(door)
door.CanCollide = true
door.Transparency = 1
end
function onChatted(msg, speaker)
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == ":open" then
local door = workspace:FindFirstChild("Door")
open(door)
end
end)
This may sound a bit silly, but are you actually firing the onChatted event? If not, you’ll need to fire it with the event, which I believe in this instance is game.Players.Chatted:Connect(onChatted(msg, speaker))
Are you sure there are no errors?
Because there’s no way the line:
if Player:GetRankInGroup(<10) then
will work without errors.
It should be
if Player:GetRankInGroup(GROUP_ID) < 10 then
Additionally, you can’t just do onChatted. You have to hook up to a player.
So your fixed code becomes:
local Players = game:GetService("Players")
local GROUP_ID = 5560221
local door = workspace:WaitForChild("Door")
local function open()
door.CanCollide = true
door.Transparency = 1
end
Players.PlayedAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if plr:GetRankInGroup(GROUP_ID) < 10 then
msg = string.lower(msg)
if msg == ":open" then
open()
end
end
end)
end)
What this does is when a player is added, it hooks up a function which hooks up a function to the on chatted event of the new player. If they have the right rank and typed the correct message, it will open the door.
local GROUP_ID = 5560221
local door = workspace:WaitForChild("Door")
game:GetService("Players").PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
if msg:sub(1,5)== ":open" then
if Player:GetRankInGroup(GROUP_ID) > 10 then
door.CanCollide = true
door.Transparency = 1
end
end
end)
end)
Printing certain parts of a script is a method used to test if certain parts of script are running. It’s usually used when Output isn’t showing anything.
Example:
local Example = 1
function CreatePart(NameofPart)
local New = Instance.New("Part")
New.Name = NameofPart
New.Parent = workspace
end
if Example == 1 then CreatePart("One")
elseif Example == 2 then CreatePart("Two")
elseif Example == 3 then CreatePart("Three")
elseif Example == 4 then CreatePart("Four")
elseif Example == 5 then CreatePart("Five")
end
-- Missing an end.
If Output wasn’t showing any errors with this script you could try:
local Example = 1
function CreatePart(NameofPart)
print("Spawn Function Success")
local New = Instance.New("Part")
New.Name = NameofPart
New.Parent = workspace
end
if Example == 1 then CreatePart("One")
elseif Example == 2 then CreatePart("Two")
elseif Example == 3 then CreatePart("Three")
elseif Example == 4 then CreatePart("Four")
elseif Example == 5 then CreatePart("Five")
end
-- Missing an end.
By doing this, you’ll see that Spawn Function Success won’t print, indicating that there’s something wrong with the elseif chain.