Suno
Suno

Reputation: 11

Roblox chat commands inside a LocalScript?

How would I make Roblox chat commands inside a LocalScript?

local Admins = {""}
local Prefix = "/" 

game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(Admins) do
    if plr.Name == v then
        plr.Chatted:Connect(function(msg)
            local loweredString = string.lower(msg)
            local args = string.split(loweredString," ")
            if args[1] == Prefix.."walkspeed" then
                for _,player in pairs(game:GetService("Players"):GetPlayers()) do
                    if string.sub(string.lower(player.Name), 1, string.len(args[2])) == 
string.lower(args[2]) then
                        player.Character.Humanoid.WalkSpeed = args[3]
                    end
                end
            end
        end)
    end
end
end)

Upvotes: 1

Views: 1057

Answers (2)

Keilorus
Keilorus

Reputation: 60

It can work in LocalScript, but I advice you to put it in a server script. The code will work for everyone because you didn't use the LocalPlayer. I also recommend making the admin table use UserId instead of Name because someone can change their name and make the script not work. And I also recommend doing if Admins[plr.UserId] then instead of iterating through the Admin table. Same with getting the target player to change speed of.

Upvotes: 2

unfestive chicken
unfestive chicken

Reputation: 373

It is possible to do this within a LocalScript, however it is certainly not advised. Anyone can exploit the functions within the script. Moving it to a server side script and using RemoteEvents are the best idea.

Upvotes: 0

Related Questions