local admins={
'mbtae1238',
'marchmellowfan7'
}
function remove(tabl,value,Mode)
assert(tabl,'seriously')
if Mode then
if value and tabl[value] then
tabl[value]=nil
return tabl
else
print('Could Not Remove "'..tostring(value or type(value))..'" because it was not in the given table')
return
end
elseif Mode==nil then
if value==nil then print('Given Obj "'..tostring(value or (type(value)))..'" wasnt in Table,Table Stays The Same') return tabl end
for i in next,tabl do
if type(i)==nil then
return
end
if tabl[i]==value then
table.remove(tabl,i)
print('removed '..tostring(value or type(value))..' at index'..i)
return tabl
else
print('Failed To Remove '..tostring(value or type(value))..' at index '..i)
if i==#tabl then print('Given Obj "'..(value or type(value))..'" wasnt in table, table stays the same') return tabl end
end
end
end
end
function insert(tabl,from,to)
assert(tabl)
tabl[from]=to
return tabl
end
--------------------
local Players_Table={}
local S_Connections={}
local G_SpyCamera=''
for i,v in next,game.Players:GetPlayers() do
Players_Table[v.Name:lower()]=v
Players_Table[v.DisplayName:lower()]=v
local connection=v.CharacterAdded:Connect(function(chr)
if tostring(v.Name)==G_SpyCamera then
workspace.Camera.CameraSubject=chr:WaitForChild'Humanoid'
elseif tostring(v.DisplayName)==G_SpyCamera then
workspace.Camera.CameraSubject=chr:WaitForChild'Humanoid'
end
end)
insert(S_Connections,v.Name:lower(),connection)
insert(S_Connections,v.DisplayName:lower(),connection)
end
game:service'Players'.PlayerAdded:Connect(function(plr)
insert(Players_Table,plr.Name:lower(),plr)
insert(Players_Table,plr.DisplayName:lower(),plr)
local connection=plr.CharacterAdded:Connect(function(chr)
if tostring(plr.Name)==G_SpyCamera then
workspace.Camera.CameraSubject=chr:WaitForChild'Humanoid'
elseif tostring(plr.DisplayName)==G_SpyCamera then
workspace.Camera.CameraSubject=chr:WaitForChild'Humanoid'
end
end)
insert(S_Connections,plr.Name:lower(),connection)
insert(S_Connections,plr.DisplayName:lower(),connection)
end)
game:service'Players'.PlayerRemoving:Connect(function(plr)
remove(Players_Table,plr.Name:lower(),'The Red')
remove(Players_Table,plr.DisplayName:lower(),'The Red')
rawget(S_Connections,plr.Name:lower()):Disconnect()
rawget(S_Connections,plr.DisplayName:lower()):Disconnect()
end)
for i,v in ipairs(admins) do
game.Players[v].Chatted:Connect(function(msg)
if rawget(Players_Table,msg:lower()) then
workspace.Camera.CameraSubject=rawget(Players_Table,msg:lower()).Character:FindFirstChild'Humanoid';
G_SpyCamera=msg:lower();
print(G_SpyCamera)
end
end)
end
You should change your title to something you actually need help with. You’re asking people to beautify this code even though your title is talking about a .Chatted event.
I’ve no idea where you got this crude code from and I have no clue as to what it is doing, so I suggest you discuss into more detail.
Im trying to make it to find players by a piece of their name now but split returns an empty array so whatever i say the player will be the first player of the playrr table , can you help
function remove(tabl,value,Mode)
assert(tabl,'seriously')
if Mode then
if value and tabl[value] then
tabl[value]=nil
return tabl
else
print('Could Not Remove "'..tostring(value or type(value))..'" because it was not in the given table')
return
end
elseif Mode==nil then
if value==nil then print('Given Obj "'..tostring(value or (type(value)))..'" wasnt in Table,Table Stays The Same') return tabl end
for i in next,tabl do
if type(i)==nil then
return
end
if tabl[i]==value then
table.remove(tabl,i)
print('removed '..tostring(value or type(value))..' at index'..i)
return tabl
else
print('Failed To Remove '..tostring(value or type(value))..' at index '..i)
if i==#tabl then print('Given Obj "'..(value or type(value))..'" wasnt in table, table stays the same') return tabl end
end
end
end
end
function insert(tabl,from,to)
assert(tabl)
tabl[from]=to
return tabl
end
--------------------
local Players_Table={}
local S_Connections;
local G_SpyCamera=''
for i,v in next,game.Players:GetPlayers() do
Players_Table[v.Name:lower()]=v
Players_Table[v.DisplayName:lower()]=v
end
game:service'Players'.PlayerAdded:Connect(function(plr)
insert(Players_Table,plr.Name:lower(),plr)
insert(Players_Table,plr.DisplayName:lower(),plr)
end)
game:service'Players'.PlayerRemoving:Connect(function(plr)
remove(Players_Table,plr.Name:lower(),'The')
remove(Players_Table,plr.DisplayName:lower(),'The')
end)
game.Players.LocalPlayer.Chatted:Connect(function(msg)
if msg:lower():find'gspy' then
msg=msg:lower()
msg=msg:split('gspy')
for i,v in ipairs(msg) do
rawset(msg,i,v:gsub(' ',''))
end
for i,v in next,msg do
if rawlen(v)==0 then
remove(msg,v,'The')
end
end
for i,v in ipairs(msg) do
print(v)
for index,value in next,Players_Table do
if index:find(v) then
print(index..' '..value.Name)
return
end
end
end
end
end)
You can read my reply to Michael . What i want is trying to spy a player by saying a piece of name of the player , but it fails , i don’t know why but it might be that the :split also returns an empty value in the table .
It’s hard to read this, your using assert a lot, if your trying to simply search for matching characters at the start of a string, it would be better to use string:match.
Everything seems to be fine in this new script , except that the characteradded functions wont work, can you help me to fix it .
local CurrentConnection;
local function Split(Text,Value)
assert(Value)
if Text:match(Value) then
local result=Text:gsub('\32',''):sub(Text:gsub('\32',''):find(Value)+rawlen(Value),rawlen(Text:gsub('\32','')))
return result
else
print[[Given Value Was Not In The Text]]
return nil
end
end
function OnChatted(Msg)
if Msg:lower():match'g_spy' then
Msg=Split(Msg:lower(),'g_spy')
for i,v in next,game:GetService'Players':GetPlayers() do
if v.Name:lower():sub(1,#Msg)==Msg then
workspace.Camera.CameraSubject=v.Character:FindFirstChild'Humanoid';
if CurrentConnection==nil then
CurrentConnection=v.CharacterAdded:Connect(function(chr)
workspace.Camera.CameraSubject=chr:FindFirstChild'Humanoid';
end)
elseif CurrentConnection then
CurrentConnection:Disconnect()
CurrentConnection=v.CharacterAdded:Connect(function(chr)
workspace.Camera.CameraSubject=chr:FindFirstChild'Humanoid';
end)
end
return
elseif v.DisplayName:lower():sub(1,#Msg)==Msg then
workspace.Camera.CameraSubject=v.Character:FindFirstChild'Humanoid';
if CurrentConnection==nil then
CurrentConnection=v.CharacterAdded:Connect(function(chr)
workspace.Camera.CameraSubject=chr:FindFirstChild'Humanoid';
end)
elseif CurrentConnection then
CurrentConnection:Disconnect()
CurrentConnection=v.CharacterAdded:Connect(function(chr)
workspace.Camera.CameraSubject=chr:FindFirstChild'Humanoid';
end)
end
return
end
end
end
end
game:GetService'Players'.LocalPlayer.Chatted:Connect(OnChatted)