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

Player ready function only teleporting one player?

Asked by 7 years ago

I attempted to make this function that ready's 2 randomly chosen players to fight:

local function readyduelers(dueler)
    dueler.Character:MoveTo(spawn1.Position)

    local swordclone = sword:Clone()
    swordclone.Parent = dueler.Backpack

    dueler.Character.Humanoid.WalkSpeed = 0
end

The code I used to choose the players and call the function:

_G.duelers = {}

local players = game.Players:GetPlayers()
local dueler1 = players[math.random(1, #players)]
repeat dueler2 = players[math.random(1, #players)] until dueler2 ~= dueler1

table.insert(_G.duelers, dueler1.Name)
table.insert(_G.duelers, dueler2.Name)

readyduelers(dueler1, dueler2)

The problem is, it's only teleporting player 1, even though I did "readyduelers(dueler1, dueler2)". I'm not sure how to fix this and any help is appreciated.

1 answer

Log in to vote
0
Answered by
VoltCode 101
7 years ago

Try:

local function readyduelers(dueler1,dueler2)
    dueler1.Character:MoveTo(spawn1.Position)

    local swordclone = sword:Clone()
    swordclone.Parent = dueler1.Backpack

    dueler.Character.Humanoid.WalkSpeed = 0

    dueler2.Character:MoveTo(spawn1.Position)

    local swordclone = sword:Clone()
    swordclone.Parent = dueler2.Backpack

    dueler2.Character.Humanoid.WalkSpeed = 0
end

_G.duelers = {}

local players = game.Players:GetPlayers()
local dueler1 = players[math.random(1, #players)]
repeat dueler2 = players[math.random(1, #players)] until dueler2 ~= dueler1

table.insert(_G.duelers, dueler1.Name)
table.insert(_G.duelers, dueler2.Name)

readyduelers(dueler1, dueler2)

The problem was that you were feeding readyduelers() two variables, but in the actual function it only had one.

Ad

Answer this question