Advertisement
Guest User

Bring Script

a guest
Sep 16th, 2023
1,154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. -- Place this script in ServerScriptService
  2.  
  3. local function getOnlinePlayers()
  4. local onlinePlayers = {}
  5. for _, player in pairs(game.Players:GetPlayers()) do
  6. if player and player:IsDescendantOf(game.Workspace) then
  7. table.insert(onlinePlayers, player)
  8. end
  9. end
  10. return onlinePlayers
  11. end
  12.  
  13. local function bringRandomPlayer(destination)
  14. local onlinePlayers = getOnlinePlayers()
  15. if #onlinePlayers > 0 then
  16. local randomPlayer = onlinePlayers[math.random(1, #onlinePlayers)]
  17. local character = randomPlayer.Character
  18. if character then
  19. local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  20. if humanoidRootPart then
  21. humanoidRootPart.CFrame = destination.CFrame
  22. end
  23. end
  24. else
  25. warn("No online players found.")
  26. end
  27. end
  28.  
  29. game.Players.PlayerAdded:Connect(function(player)
  30. player.Chatted:Connect(function(message)
  31. if message:lower() == "!bring" then
  32. local destination = game.Workspace.BringDestination -- Change this to your desired destination
  33. if destination and destination:IsA("BasePart") then
  34. bringRandomPlayer(destination)
  35. else
  36. warn("Bring destination not found.")
  37. end
  38. end
  39. end)
  40. end)
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement