Hello, I’m in a need of help with a script.
This script is supposed to pick a random player, and change their team to Bright Violet, and the rest of the players would be Bright Red. But I’m not sure why this script runs multiple times. How can I make it run only once?
local Motherscript = {}
function Motherscript.Execute()
local players = game:GetService("Players"):GetPlayers()
local hostIndex = math.random(1, #players)
local hostPlayer = players[hostIndex]
local hostTp = workspace.HostTp
local candidatesTp = workspace.CandidatesTp
local function TeleportPlayer(player, position, teamColor)
if player.Character then
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid and humanoid.Sit then
humanoid.Sit = false
end
wait(0.1)
if player.Character:FindFirstChildOfClass("Seat") then
player.Character:SetPrimaryPartCFrame(CFrame.new(position))
else
player.Character:MoveTo(position)
end
end
player.TeamColor = teamColor
end
hostPlayer.Team = game:GetService("Teams"):FindFirstChild("Host")
TeleportPlayer(hostPlayer, hostTp.Position, BrickColor.new("Bright violet"))
local candidatesTeam = game:GetService("Teams"):FindFirstChild("Candidates")
local brightRedColor = BrickColor.new("Bright red")
for i, player in ipairs(players) do
if i ~= hostIndex then
player.Team = candidatesTeam
TeleportPlayer(player, candidatesTp.Position, brightRedColor)
end
end
print("Executing ModuleScript...")
end
return Motherscript
Screenshot from one of the tests