Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This script won't call the function, what do I do?

Asked by
TheePBHST 154
7 years ago

So, I wanted the script to call the function's ChangeTeam and Lobby but it won't call those two functions. I'm totally confused.

IntermissionTime = 10
RoundTime = 60
IntermissionString = "Intermission: %s" -- can be any string, put %s where you want the time to be displayed
RoundString = "Time Left: %s" -- can be any string, put %s where you want the time to be displayed

GetTime = Instance.new("RemoteFunction")
GetTime.Name = "GetTime"
GetTime.Parent = game.Workspace

function GetTime.OnServerInvoke()
    local T = {}
    table.insert(T, String)
    table.insert(T, CurrentTime)
    return T
end

function CountTime()
    while CurrentTime > 0 do
        wait(1)
        CurrentTime = CurrentTime -1
    end
end

function ChangeTeam()
    local currentPlayers = game.Players:GetPlayers() --Collect all players
    local currentTeams = game.Teams:GetChildren() --Collect all teams
    --Get a random player, and a random team
    local randomPlayer = currentPlayers[math.random(1,#currentPlayers)]
    local randomTeam = currentTeams[math.random(1,#currentTeams)]
    randomPlayer.Team = randomTeam
end

function Lobby()
    local currentPlayers = game.Players:GetPlayers() --Collect all players
    local currentTeams = game.Teams.BattleGofLobby --Collect all teams
    local Lobby = currentTeams
    currentPlayers.Team = Lobby
end

while wait() do
    String = IntermissionString
    Lobby() 
    CurrentTime = IntermissionTime 
    CountTime()
    String = RoundString
    ChangeTeam()
    CurrentTime = RoundTime
    CountTime()
end


0
It probably does call them. Use http://wiki.roblox.com/index.php?title=Lua_debugger to make sure. cabbler 1942 — 7y
0
It look correct to me. Does it throw any errors in output? shadownetwork 233 — 7y
0
Nope. TheePBHST 154 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

Lobby doesn't do anything. You assign a specific team to the table of players you have. This doesn't assign each player in the list to the team, it just makes a new field in the table.

Instead, use a for loop:

for _, player in ipairs(currentPlayers) do
    player.Team = Lobby
end

Note that your ChangeTeam function does little better -- it assigns a random team to a single player. You should at least do that for every player; you may also want to try to balance the teams (if a team has more players than another team, don't put more players on it).

0
I've gotten it fixed already by Goulstem, thanks for the request! TheePBHST 154 — 7y
0
TheePBHST: Glad you got it working. Ideally you should either accept an answer or modify the title to say "Solved" so anyone going through the questions won't stop to read this one. chess123mate 5873 — 7y
Ad

Answer this question