Basically, I was just fiddling around with a script I found, modifying it to fit what I want. The first condition works for player1, but player2’s condition doesn’t work. I’ve tried multiple times to get it to work, rewriting that part of the script in different ways, but it never seems to function. I’m just wondering where I should go from here with this script, so that it can actually work with that else condition.
local votec = game.ReplicatedStorage:FindFirstChild("voteclient")
local vote = game.ReplicatedStorage:FindFirstChild("vote")
local sound = Instance.new("Sound", game.Workspace)
local presidente = game.Teams:FindFirstChild("El presidente")
sound.SoundId = "rbxassetid://5350922498"
vote.OnServerEvent:Connect(function(player)
local Players = game:GetService('Players')
local function ChooseRandomPlayer()
local Player = nil
local CurrPlayers = Players:GetPlayers()
local R = Random.new(tick())
local Num = R:NextInteger(1, #CurrPlayers)
Player = CurrPlayers[Num]
return Player
end
if not (#Players:GetPlayers() < 2) then
local Player1 = ChooseRandomPlayer()
wait(5)
local Player2 = Player1
while Player2 == Player1 do
Player2 = ChooseRandomPlayer()
wait()
end
print(Player1, Player2)
game.Workspace.votemodel.part.SurfaceGui.TextLabel.Text = Player1.Name
game.Workspace.votemodel2.part.SurfaceGui.TextLabel.Text = Player2.Name
player.PlayerGui.election.Enabled = true
sound:Play()
task.wait(10)
player.PlayerGui.election.Enabled = false
task.wait(40)
if game.Workspace.vote.Value >= game.Workspace.vote2.Value then
if player.Name == Player1.Name then player.Team = presidente
else
if player.Name == Player2.Name then player.Team = presidente
end
end
end
end
end)
There’s no error, which is kinda the biggest problem for me.
The script basically does this: find random player, find other random player.
those two players are now named player1 and player2. if player 2 is the same as player1, then it does the math again until they aren’t the same.
the last part of the script changes two textlabels so that they’ll have the name of the two players, then it enables the election gui, waits 10 seconds, disables it. then it checks if the vote value for player1’s vote machine is higher than player2’s vote value, if so, it makes player1 join a team called “el presidente”.
the issue is that the code after the else doesn’t seem to work.
It’s not a fault with else itself, it’s a problem with the script, but I cannot figure out what makes it not work.
as I said in the first part of this whole post, I was just fiddling with a script.
I had seen similar things as to that be done, but I specifically wanted only 2 players, and I wanted to get their names. A lot of scripts I was seeing as examples seemed to get several players, and due to my lack of scripting knowledge, I just went with this script that I found. If that’d be a better way of achieving my goal, please say so.
local votec = game.ReplicatedStorage:FindFirstChild("voteclient")
local vote = game.ReplicatedStorage:FindFirstChild("vote")
local sound = Instance.new("Sound", game.Workspace)
local presidente = game.Teams:FindFirstChild("El presidente")
sound.SoundId = "rbxassetid://5350922498"
vote.OnServerEvent:Connect(function(player)
local Players = game:GetService('Players')
local function ChooseRandomPlayer()
local Player = game.Players:GetPlayers()[math.random(0, #game.Players:GetPlayers())]
return Player
end
if #Players:GetPlayers() > 2 then
local Player1 = ChooseRandomPlayer()
local Player2 =ChooseRandomPlayer()
while Player2 == Player1 do
Player2 = ChooseRandomPlayer()
end
print(Player1, Player2)
game.Workspace.votemodel.part.SurfaceGui.TextLabel.Text = Player1.Name
game.Workspace.votemodel2.part.SurfaceGui.TextLabel.Text = Player2.Name
player.PlayerGui.election.Enabled = true
sound:Play()
task.wait(10)
player.PlayerGui.election.Enabled = false
task.wait(5)
if game.Workspace.vote.Value >= game.Workspace.vote2.Value then
if player.Name == Player1.Name then player.Team = presidente end
else
if player.Name == Player2.Name then player.Team = presidente end
end
end
end)
I’ve tried that script, but it doesn’t seem to do the math correctly(or something else, perhaps). It never makes its way to print Player1 and Player2, or activate the election GUI. There was a misspelling I noticed(an equal symbol being put into a word), but removing it didn’t seem to fix it. I think I’m just really lost on this all
local votec = game.ReplicatedStorage:FindFirstChild("voteclient")
local vote = game.ReplicatedStorage:FindFirstChild("vote")
local sound = Instance.new("Sound", game.Workspace)
local presidente = game.Teams:FindFirstChild("El presidente")
sound.SoundId = "rbxassetid://5350922498"
vote.OnServerEvent:Connect(function(player)
local Players = game:GetService('Players')
local function ChooseRandomPlayer()
local Player = game.Players:GetPlayers()[math.random(0, #game.Players:GetPlayers())]
return Player
end
if #Players:GetPlayers() > 2 then
local Player1 = ChooseRandomPlayer()
local Player2 =ChooseRandomPlayer()
repeat
Player2 = ChooseRandomPlayer()
until Player2 ~= Player1
print(Player1, Player2)
game.Workspace.votemodel.part.SurfaceGui.TextLabel.Text = Player1.Name
game.Workspace.votemodel2.part.SurfaceGui.TextLabel.Text = Player2.Name
player.PlayerGui.election.Enabled = true
sound:Play()
task.wait(10)
player.PlayerGui.election.Enabled = false
task.wait(5)
if game.Workspace.vote.Value >= game.Workspace.vote2.Value then
if player.Name == Player1.Name then player.Team = presidente end
else
if player.Name == Player2.Name then player.Team = presidente end
end
end
end)
well, I’m pretty sure I’ve just failed to connect the function at the end or something alike that, as the part that fails to fire is the ChooseRandomPlayer function(tested by printing in different parts of the script).
I’ll mark this as the solution, and I’ll try to figure however I’m meant to connect things like this. Thanks for your help!