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

Script that works only if there's 1 object in a folder, but works even if there's multiple?

Asked by
soutpansa 120
5 years ago
Edited 5 years ago

This is a lot to explain but I'll try my best, and I will explain further if need be. I'm making a tournament system for a project, and there's a folder in the workspace called "Roster". When the player enters a que for the tourney, it places an int value into the folder, then names the int value what the player is named. After 2 min of waiting, all of those in the que will be teleported to the arena and they can fight. But instead of that happening, when the players load in, after about 10 seconds it just chooses a random one to win and that's it. The intvalue is not deleted from the folder until the player dies, so I'm not sure why it does this. Here is the script:

while true do
    wait()
local Roster = workspace.Roster:GetChildren()
    for i = 1, #Roster do
        if #Roster == 1 then
            wait(130)
            if #Roster == 1 and workspace.Winner.Value == "" and workspace.QueCountdown.Value == 0 then
            workspace.TourneyTime.Value = 20
            workspace.TourneyTime.Countdown.Disabled = false
            workspace.QueCountdown.Value = 2
            workspace.QueCountdown.Countdown.Disabled = false
            local Entry = workspace.Roster:FindFirstChild(Player.Name)
            if Entry ~= nil then
            workspace.Winner.Value = Entry.Name
            local Message = Instance.new("Message")
            Message.Parent = workspace
            Message.Text = ""..workspace.Winner.Value.." Has Won the Tourney. Glory to their house!"
            local Rekt = workspace.RemoveMessageScript:Clone()
            Rekt.Parent = Message
            Rekt.Disabled = false
            local Reward = math.random(1,5000)
            if Reward ~= 5000 and Player.Name == workspace.Winner.Value then
                Player.Stats.Money.Value = Player.Stats.Money.Value + 1000
                Player.Character.Humanoid.Health = 0
            elseif Reward == 5000 and Player.Name == workspace.Winner.Value then
                print("WIP")
                Player.Character.Humanoid.Health = 0
                    end         
                end
            end
        end
    end
end

here is the script that inserts the intvalues

script.Join.OnServerEvent:Connect(function(Player)
    if workspace.TourneyTime.Value <= 0 then
        Player.NonStats.TourneyValue.Value = 1
        local Pos = math.random(1,5)
        if Pos == 1 then
            Player.Character.HumanoidRootPart.CFrame = workspace.Que1.CFrame
            local Ticket = Instance.new("IntValue")
            Ticket.Name = play.Name
            Ticket.Parent = workspace.Roster
        elseif Pos == 2 then
            Player.Character.HumanoidRootPart.CFrame = workspace.Que2.CFrame
            local Ticket = Instance.new("IntValue")
            Ticket.Name = play.Name
            Ticket.Parent = workspace.Roster
        elseif Pos == 3 then
            Player.Character.HumanoidRootPart.CFrame = workspace.Que3.CFrame
            local Ticket = Instance.new("IntValue")
            Ticket.Name = play.Name
            Ticket.Parent = workspace.Roster
        elseif Pos == 4 then
            Player.Character.HumanoidRootPart.CFrame = workspace.Que4.CFrame
            local Ticket = Instance.new("IntValue")
            Ticket.Name = play.Name
            Ticket.Parent = workspace.Roster
        elseif Pos == 5 then
            Player.Character.HumanoidRootPart.CFrame = workspace.Que5.CFrame
            local Ticket = Instance.new("IntValue")
            Ticket.Name = play.Name
            Ticket.Parent = workspace.Roster
        end
    end
end)

again, Im sorry if it is a lot. I will do my best to explain further if you need me to. Thanks for reading

1
Messages are deprecated User#19524 175 — 5y
0
I appreciate it but uh.. what does that have to do with my question? Sorry if I come off a little rude, but I know that it is deprecated. I'm only using it for testing purposes at the moment. I do appreciate your concern though soutpansa 120 — 5y

Answer this question