New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
2

Trying to give every player a target (another player)?

Asked by
Mystdar 352 Moderation Voter
4 years ago

I am trying to give everyone a target and a person targeting them, so person a might be targeting person b but is being targeted by person c. I have tried this, I do not believe it will work, but I can't test it in studio, because it requires multiple people. I have a problem because what if person a's target is person b and person b's target is person a and there are only 3 people in the server, person C will have no one to target. I can't make it so you can't target your hunter otherwise the final two won't be able to hurt each other. This is my script:

--[[Values]]
--[[Tables]]
Players = game.Players:GetChildren() -- Table of players

--[[Checking alive players]]
if player.TeamColor ~= "Grey" then

Colours = {
    BrickColor.new("Sand red"),
    BrickColor.new("Sand blue"),
    BrickColor.new("Sand green"),
    BrickColor.new("New yeller"),
    BrickColor.new("Br. yellowish orange"),
    BrickColor.new("Lavender"),
    BrickColor.new("Dusty Rose"),
    BrickColor.new("Deep blue")
}

--[[Colouring]]
function Assign()
    for a = 1, Players do
        a.Character.Parent.Torso.BrickColor = Colours[a]
    end
end

--[[Current players (The players still alive)]]
function Alive()
    Current = Players
    for i in Current do
        if i.TeamColor ~= "Grey" then
            Current.remove(i)-- No idea how to use this
        end
    end
    if #Current == 1 then
        Win()
    elseif #Current == 0 then
        Target() -- Start again
    end
end

--[[Selecting Hunters/Targets]]
function Select()
    b = Players[math.random(1, Current)] -- Random player 
    if a ~= b and a. Target == nil then
        a.Target.Value = b.Name
        b.Hunter.Value = a.Name
        print (a.."/'s target is:"..b)
        print (b.."\'s hunter is:"..a)
    elseif a == b then
        Select()
    end
end

--[[Win]]
function Win()
    print (Current[1].." won!")
    Target()
end

--[[Target, Hunter]]
function Target()
    Assign()
    Alive()
    for a = 1, Current do
        Select()
    end
end

wait(5)
Target()
1
You can test it with multiple people in studio. Just go under the 'Test' tab in studio, then find the "Start" button. Click it and it will start a server with the number of players specified in the box next to it. http://wiki.roblox.com/index.php?title=Studio#Test_2 Perci1 4916 — 4y
0
Thank you, I wasn't aware Mystdar 352 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago

Line 3.

You want to put that in a loop, otherwise it'd only be the first person that joined. Try making a PlayerAdded function and then assign the variable in the function.

edit:

--[[Colouring]]
20
function Assign()
21
    for a = 1, #Players do --add a hashtag to get the amount of stuff in a table. You originally had Players
22
        a.Character.Parent.Torso.BrickColor = Colours[a]
23
    end
24
end

1
Any advice on any other things? Mystdar 352 — 4y
1
Updated @Mystdar 0xDEADC0DE 310 — 4y
1
Thanks Mystdar 352 — 4y
Ad

Answer this question