Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- game:GetService("StarterGui"):SetCore("SendNotification",{
- Title = "Script /goto players",
- Text = "Script a ÊtÊ executer",
- Icon = "rbxassetid://11823384169",
- Duration = 15
- })
- local ChatEvent = game:GetService("ReplicatedStorage").DefaultChatSystemChatEvents
- function starts_with(str, start)
- -- returns true if "str" begins with "start"
- -- example: input "Forever", "For"
- -- output: true
- return str:sub(1, #start) == start
- end
- function get_array_selection_from_incomplete(incomplete, selection)
- -- takes an incomplete string and finds the first match in an array
- -- example: input "thi" searching in array ("ones","twos","thirds","fourths")
- -- output -> "thirds"
- for i, v in pairs(selection) do
- if starts_with(v, incomplete) then
- return selection[i]
- end
- end
- end
- ChatEvent.OnMessageDoneFiltering.OnClientEvent:Connect(function(obj)
- -- We want to make sure we're always using an updated list of players, so we create a "Players" variable everytime a message is sent
- local Players = game:GetService("Players")
- -- LocalPlayer is just us
- local lPlayer = Players.LocalPlayer
- -- "obj" is the literal message object (it can be named anything) which contains info on the message sent
- -- obj contains 2 variables of interest:
- -- "Message": just the contents of the message
- -- and "FromSpeaker": the username of the person who sent the message
- -- When a message is sent, we want to check if the contents starts with "/app ":
- if starts_with(obj.Message, "/goto ") then
- -- Now, we want to use the rest of the message to check for a player with a username
- -- Here, we make a variable that cuts the message off by 6 characters (literally, substring of 7 characters, that's why it says 6)
- local check_username = obj.Message:sub(7)
- -- Create an array with each player's username
- local Usernames = {}
- for i, v in pairs(game.Players:GetChildren()) do
- table.insert(Usernames, v.Name)
- end
- -- Get the corrected username
- check_username = get_array_selection_from_incomplete(check_username, Usernames)
- -- Now, we iterate over each player in the server to check if it matches with the corrected string
- for i,v in pairs(game.Players:GetChildren()) do
- -- The variable "v" is the player object, so we check for v.Name
- if v.Name == check_username then
- -- We now have a matching player, so we'll teleport ourselves to them using the variables defined top-level
- lPlayer.Character.HumanoidRootPart.CFrame = Players[v.Name].Character.HumanoidRootPart.CFrame
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement