Advertisement
MaxproGlitcher

Code tp /goto Max

Dec 26th, 2022 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. game:GetService("StarterGui"):SetCore("SendNotification",{
  2. Title = "Script /goto players",
  3. Text = "Script a ÊtÊ executer",
  4. Icon = "rbxassetid://11823384169",
  5. Duration = 15
  6. })
  7. local ChatEvent = game:GetService("ReplicatedStorage").DefaultChatSystemChatEvents
  8.  
  9. function starts_with(str, start)
  10. -- returns true if "str" begins with "start"
  11. -- example: input "Forever", "For"
  12. -- output: true
  13. return str:sub(1, #start) == start
  14. end
  15.  
  16. function get_array_selection_from_incomplete(incomplete, selection)
  17. -- takes an incomplete string and finds the first match in an array
  18. -- example: input "thi" searching in array ("ones","twos","thirds","fourths")
  19. -- output -> "thirds"
  20. for i, v in pairs(selection) do
  21. if starts_with(v, incomplete) then
  22. return selection[i]
  23. end
  24. end
  25. end
  26.  
  27. ChatEvent.OnMessageDoneFiltering.OnClientEvent:Connect(function(obj)
  28. -- 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
  29. local Players = game:GetService("Players")
  30. -- LocalPlayer is just us
  31. local lPlayer = Players.LocalPlayer
  32. -- "obj" is the literal message object (it can be named anything) which contains info on the message sent
  33. -- obj contains 2 variables of interest:
  34. -- "Message": just the contents of the message
  35. -- and "FromSpeaker": the username of the person who sent the message
  36. -- When a message is sent, we want to check if the contents starts with "/app ":
  37. if starts_with(obj.Message, "/goto ") then
  38. -- Now, we want to use the rest of the message to check for a player with a username
  39. -- Here, we make a variable that cuts the message off by 6 characters (literally, substring of 7 characters, that's why it says 6)
  40. local check_username = obj.Message:sub(7)
  41. -- Create an array with each player's username
  42. local Usernames = {}
  43. for i, v in pairs(game.Players:GetChildren()) do
  44. table.insert(Usernames, v.Name)
  45. end
  46. -- Get the corrected username
  47. check_username = get_array_selection_from_incomplete(check_username, Usernames)
  48. -- Now, we iterate over each player in the server to check if it matches with the corrected string
  49. for i,v in pairs(game.Players:GetChildren()) do
  50. -- The variable "v" is the player object, so we check for v.Name
  51. if v.Name == check_username then
  52. -- We now have a matching player, so we'll teleport ourselves to them using the variables defined top-level
  53. lPlayer.Character.HumanoidRootPart.CFrame = Players[v.Name].Character.HumanoidRootPart.CFrame
  54. end
  55. end
  56. end
  57. end)
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement