Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make commands like "/[cmd]?"

Asked by 5 years ago

So I wondering, how to make a command my how do I make it if that person has perms it will work so I was trying to make a command that does. If I say "/update" then EVERYONE THAT IS PLAYING THE GAME TELEPORTS TO A GAME FOR 15 SECONDS THEN THEY TELEPORT BACK. this is for the game to get updated. Any forum or script examples thank you. :D Have a nice day.

0
I just want help with 1 command Alibolly 10 — 5y
0
I deleted my other post because no one understood it. So heres a diff one. Alibolly 10 — 5y
0
Check out my question Global Announcement System not responding. It’s still new so just scroll for a bit and you’ll find the answer you’re looking for. It’s the exact syntax for commands Ziffixture 6913 — 5y
0
I awnsered your question :) now all is left is the reputation and the green checkmark RBLXNogin 187 — 5y

2 answers

Log in to vote
0
Answered by
EmK530 143
5 years ago
Edited 5 years ago

Unsure how to make so the players get teleported back, you'd probably have to script that in the other place yourself.

For teleporting everyone to another place you can use this.

local placeID = 180364455
local teleportMessage = "teleport"
local admin = "Alibolly"

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(string)
        if string == teleportMessage and tostring(plr) == admin then
            local TS = game:GetService("TeleportService")
            for i = 1, #game.Players:GetChildren() do
                TS:Teleport(placeID, game.Players:GetChildren()[i])
            end
        end
    end)
end)

There are some values that you can change for your preferences.

If you don't want to get teleported yourself, then this script will exclude you from being teleported.

local placeID = 180364455
local teleportMessage = "teleport"
local admin = "Alibolly"

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(string)
        if string == teleportMessage and tostring(plr) == admin then
            local TS = game:GetService("TeleportService")
            for i = 1, #game.Players:GetChildren() do
                if not game.Players:GetChildren()[i].Name == admin then
                    TS:Teleport(placeID, game.Players:GetChildren()[i])
                end
            end
        end
    end)
end)

Haven't tested if it works with all players, only one player. But hopefully this works :)

0
This is a bad awnser. She/He wants to make commands. Please update your awnser or I will have to get it a downvote RBLXNogin 187 — 5y
0
Will you read the question? He/She wanted to make a command to teleport everyone to another place and then back. You can also change the teleportMessage to something else. So if I change it to ":teleporteveryone" then he has to say :teleporteveryone to use the command. Pretty obvious that it's possible to change the message string to be anything. Don't abuse your high reputation please. EmK530 143 — 5y
Ad
Log in to vote
0
Answered by
RBLXNogin 187
5 years ago

Hello there, RBLXNogin here and I have a solution to your problem. You have two issues: writing commands, and the ability to only let admins to them. Well, in that case let me introduce something known as "Chatted", which is an event to control what happens when a message is sent. You can manipulate this in order to make a /cmd (aka detecting when the command is typed). First, let me give you a quick definition of ROBLOX events.

An event is when a set of instructions are run into the application (ROBLOX GAME), when a certain action is completed. Here is a basic example of a event:

game.Workspace.Part.Touched:Connect(function(hit)
    print("The part has been touched!")
end)

This code detects when the action of workspace.Part is touched, and if so then it will execute the following code. Understand? The "Touched" event has to be a "member" of the object that you want to give the event to. Well into a typical Chatted event we want to detect which player talked. In that scenario, we need to first use PlayerAdded inorder to pass a plr parameter. PlayerAdded is an event that executes when a new player joins the game, and we can pass a player parameter. Here is an example:

game.Players.PlayerAdded:Connect(function(plr)
    --code for when a player joins the game
end)

In order to activate chatted, we need to make it a member of the "plr" parameter.

game.Players.PlayerAdded:Connect(function(plr)
    --code for when a player joins the game
    plr.Chatted:Connect(function(msg)
        --code for when that player says something in Chat
    end)
end)

Now do you understand? So far our script detects when a player joins the game and says something in chat. Everytime a player activated the Chatted event by using a message, we can detect what is is, and most importantly, if it is a command. Here for example let me show you a basic :KickMe command:

game.Players.PlayerAdded:Connect(function(plr)
    --code for when a player joins the game
    plr.Chatted:Connect(function(msg)
        if msg == ":KickMe()" then
            --Code for when a player types ":KickMe"
            plr:Kick("You have been kicked yourself from the server") 
        end
    end)
end)

Perfect! Now see how we can use Chatted events to make your own command? Here is another good example:

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        if msg == "/addBrick" then
            local part = Instance.new("Part")
            part.Parent = workspace.
            part.Position = Vector3.new(0,0,0)
        end
    end)
end)

The command above says that when you type "/addBrick" it creates a brick in the workspace with the coordinates (0,0,0). Pretty neat huh?

The last solution is to make only certain players able to do this. Here you have to detect is the player is allowed, then execute the code. Here is how you will accomplish this:

game.Players.PlayerAdded:Connect(function(plr)
    if plr.Name == "RBLXNogin" then --Name of Admin
        plr.Chatted:Connect(function(msg)
            if msg == "/poo" then
                print("RBLXNogin, the admin, has typed 'poo'")
            end
        end)
    end

See that? This is the basics to making your own custom admin commands. Now all is that is left is for you to mark my awnser and help me gain reputation on ScriptingHelpers :)

0
Begging for upvotes while calling other decent answers bad. That's a bad thing to do. EmK530 143 — 5y

Answer this question