Message script is not working

This script in Server Script Service
doesn’t work.

1 Like

Well what exactly doesn’t work?
Any errors?
Can describe the problem?

Within your conditional statement for admin checking, you’re attempting to index admins as if it’s a dictionary when it’s an array.

...tableContains(admins, player.Name) and >>>admins[player.Name]<<< then

Try removing that index check and see what happens.

2 Likes

You do not need a custom table.find() function. You can just do table.find(admins, player.Name)

Also, are you connecting events to these functions?

1 Like

Adding on top of @TheeDeathCaster’s reply, you should save Admin’s UserIds instead of their Roblox names so when they change their Roblox name the system can detect them and you don’t need a custom function like tableContains() when table.find() exist.

2 Likes

the problem. I can’t see the error but it doesn’t work

1 Like

Did you connect the functions to events? If not, nothing is running.

1 Like

it all connect on an event. but it still doesn’t work

1 Like

Did you try removing the index check that I brought up earlier?
EDIT
In other words, did you try changing your code to the below?

if msg == "OpenGui" and table.find(admins, player.Name) then

EDIT2
Can you please share your entire script if possible, and not by screenshot preferably? @Dquvo

1 Like

Yes i did but again doesn’t work i send again code.

1 Like

Try adding print statements around your code and see if they print, that will help you narrow down what isn’t working

Yes it’s didn’t work i don’t know where is the problem.

1 Like

Can you please share your entire script? Preferably not by screenshot?

1 Like

So did none of them print? or did some of them print? if so which ones?

local admins = {

"BloomyL",
"TrollTroller404",
"AfrashQuadra",
"OkNiceShoot",
"Space_TR",
"T3K7H3CKD3DI", 
"EllitleLordNihat",
"YigitSoKawaii",
"Dquvo"

}
local replicatedstorage = game:GetService(“ReplicatedStorage”)
local OfficialEvent = replicatedstorage:WaitForChild(“AdminGui”)
local player = game.Players.LocalPlayer

function tableContains(t, value)
for _, v in pairs(t) do
if v == value then
return true
end
end
return false
end

function onChatted(msg, player)
if msg == “OpenGui” and tableContains(admins, player.Name) and admins[player.Name] then
local GUI = game.ServerScriptService.Command.AdminGui
GUI:Clone().Parent = player.PlayerGui
end
end

– here is code

1 Like

There no events the functions are not being called
You need events to have your code work

none of them print. Can you copy the code and tell me where is the error?

1 Like

If that’s your entire script, there’s no events set up to call the method onChatted.
Try adding the below to the script.

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        onChatted(msg, player)
    end)
end)
1 Like

This is a LocalScript, you cannot define something in ServerScriptService. And if this is a Server Script, you cannot define the LocalPlayer.

Therefore, either you can’t get the player or you can’t get the Gui.

You also didn’t connect the Chatted event, which doesn’t run the function.

1 Like