I have a system message that should show up every time an admin joins:
Scripts
Main Script in ServerScriptService
--// Services \\--
local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild('ChatService'))
--// Settings \\--
local Prefix = '/'
local Admins = {}
Admins[216571167] = {Rank = 'Owner', Name = 'foodislife345678'}
Admins[118600368] = {Rank = "Friend", Name = 'untred'}
--// Variables \\--
local AdminJoinedEvent = ReplicatedStorage.AdminJoined
--// Functions \\--
local function checkForTarget(target)
if not target then
warn('Target not found!')
else
print('Target found!')
end
end
--// Commands \\--
local function onPlayerAdded(Player)
if Admins[Player.UserId] then
AdminJoinedEvent:FireAllClients(Player)
Player.Chatted:Connect(function(msg)
local loweredString = string.lower(msg)
local args = string.split(loweredString," ")
local args2 = string.split(loweredString, ",")
--/time <add/set> <time>
if args[1] == Prefix..'time' then
local typ = args[2]
local time_ = args[3]
if typ == 'set' then
Lighting.ClockTime = time_
if time_ == 'day' then
Lighting.ClockTime = 14
end
if time_ == 'night' then
Lighting.ClockTime = 0
end
end
if typ == 'add' then
Lighting.ClockTime = Lighting.ClockTime + time_
end
if typ == 'subtract' then
Lighting.ClockTime = Lighting.ClockTime - time_
end
end
--/kill <target>
if args[1] == Prefix..'kill' then
local target = args[3] and Players:FindFirstChild(args[2])
local valid = target and checkForTarget(target)
if valid then
target.Character:BreakJoints()
end
Player.Character:BreakJoints()
end
--/gamemode <gamemode> <target>
if args[1] == Prefix..'gamemode' then
local gamemode = args[2]
local target = args[3] and Players:FindFirstChild(args[3])
local valid = target and checkForTarget(target)
if valid then
if gamemode == 'creative' or '1' or 'c' then
target.Character.Humanoid.MaxHealth = math.huge
target.Character.Humanoid.Health = 9e9
end
if gamemode == 'survival' or '0' or 's' then
target.Character.Humanoid.MaxHealth = 100
target.Character.Humanoid.Health = target.Character.Humanoid.MaxHealth
end
end
if gamemode == 'creative' or '1' or 'c' then
Player.Character.Humanoid.MaxHealth = math.huge
Player.Character.Humanoid.Health = 9e9
end
if gamemode == 'survival' or '0' or 's' then
Player.Character.Humanoid.MaxHealth = 100
end
end
--/tp|teleport <X,Y,Z/target>
if args[1] == Prefix..'teleport' or args[1] == Prefix..'tp' then
local X = args[2]
local Y = args2[3]
local Z = args2[4]
local target = Players:FindFirstChild(args[2])
local valid = target and checkForTarget(target)
if valid then
Player.Character.HumanoidRootPart.CFrame = target.Character.HumanoidRootPart.CFrame
end
Player.Character.HumanoidRootPart.CFrame = CFrame.new(X,Y,Z)
end
end)
end
end
for _, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Localscript in StarterGui
local StarterGui = game:GetService("StarterGui")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AdminJoinedEvent = ReplicatedStorage:WaitForChild('AdminJoined')
local Admins = {}
Admins[216571167] = {Rank = 'Owner', Name = 'foodislife345678'}
Admins[118600368] = {Rank = "Friend", Name = 'untred'}
AdminJoinedEvent.OnClientEvent:Connect(function(plr)
local rank = Admins[plr.UserId]["Rank"]
local name = Admins[plr.UserId]["Name"]
if rank == 'Owner' then
StarterGui:SetCore('ChatMakeSystemMessage', {
Text = "{System}: The owner has joined!",
Color = Color3.new(255,255,255),
Font = Enum.Font.SourceSansBold,
TextSize = 20
})
else
StarterGui:SetCore('ChatMakeSystemMessage', {
Text = "{System}: "..rank.." "..name.." has joined!",
Color = Color3.new(255,255,255),
Font = Enum.Font.SourceSansBold,
TextSize = 20
})
end
end)
The thing is, it doesn’t work in the actual game, and only works in studio.
And when I check the console, there are no errors or anything.
If you know how I can fix this then please tell me!
– food