Basically, I’ve completed the bare-bones structure for the election system in my game, but before I go any further, I would like feedback on the current code. The first script originally had a onplayeradded function, but that would cause the player who joined to be unable to actually see the election GUI.
I’ve also noticed there’s a slight delay between when the GUIs appear for each player in this current rendition, which isn’t exactly what I’d like.
(P.S the “break” in the first script is just until I find a better solution)
Localscript that triggers the election:
local team = game.Teams["El presidente"]
local civilian = game.Teams.Civilian
local remoteEvent = game.ReplicatedStorage:FindFirstChild("vote")
local Players = game:GetService("Players")
while true do
wait(4)
if #team:GetPlayers() == 0 then
if #civilian:GetPlayers() == 2 then
print("election")
remoteEvent:FireServer()
break
end
end
end
Serverscript that gets fired by that localscript:
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://9071337529"
vote.OnServerEvent:Connect(function(player)
local Players = game:GetService('Players')
wait(8)
votec:FireClient(player)
end)
localscript that is fired by the serverscript:
local votec = game.ReplicatedStorage:FindFirstChild("voteclient")
local player = game:GetService("Players").LocalPlayer
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9071337529"
local function onClientEventFired()
print("Hello")
player.PlayerGui.election.Enabled = true
sound:Play()
task.wait(10)
player.PlayerGui.election.Enabled = false
player.PlayerGui.register.Enabled = true
end
votec.OnClientEvent:Connect(onClientEventFired)