Keep in mind that I'm only a beginner so please try to explain each detail so I can learn from this. I needed to add something to my script, but I'm not sure how to do that exactly, the Server Script below is supposed to pick a random moderator from a table and teleport them to the caller which is the player who triggered the RemoteEvent, it works perfectly when it picks someone in-game while when it picks someone else not in-game it prints that the moderator couldn't be teleported and no moderators are teleported, I wanted to make it so if the moderator picked can't be found in-game then the function would repeat until a moderator is found in-game and gets teleported to the caller. I have asked this before but nobody answered and I managed to improve it a little myself so I decided to ask once again, below you can check what I have done so far.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teleport = ReplicatedStorage.Teleport
local function ModeratorCaller(player)
local table = {"DukeOfWorms", "Moderator1", "Moderator2"}
local Players = game:GetService("Players")
local random = math.random(1, #table)
local chosen = table[random]
if Players:FindFirstChild(chosen) then
game.Workspace[chosen].HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame
print("The moderator ".. Players[chosen].Name .." has been teleported to the player ".. player.Name)
elseif not Players:FindFirstChild(chosen) then
print("The moderator chosen couldn't be found in-game and therefore couldn't be teleported to the player " .. player.Name)
end
end
Teleport.OnServerEvent:Connect(ModeratorCaller)

1 comment
Using "Debounce"?