I am currently working on a system to vote for players in the server. When a block is pressed (will move it to ServerScriptService later) it will display a GUI of all the player’s names. When a button is pressed on a player’s screen, it will remove the GUI and they will get a vote.
For some reason, when I press the button on my screen, I get all the players in the server; however on my alt’s screen, it only shows the alt’s name. Here is the script I believe has the issue
below:
ClickScript (this is the script inside the part I click to activate the GUI)
local players = game:GetService("Players")
local rs = game.ReplicatedStorage
local votingAssets = rs.VotingAssets
local votingGui = votingAssets.VotingGui
local votingScript = votingAssets.VotingScript
local voteSave = votingAssets.VoteSave
local part = script.Parent
local cd = part.ClickDetector
cd.MouseClick:Connect(function()
for i,v in pairs(votingGui.Frame:GetChildren()) do
if v:IsA("TextButton") then
v:Destroy()
end
end
for i,v in pairs(voteSave:GetChildren()) do
v:Destroy()
end
for i,v in pairs(players:GetChildren()) do
local vButton = Instance.new("TextButton")
vButton.Text = v.Name
vButton.Parent = votingGui.Frame
votingScript:Clone().Parent = vButton
votingGui:Clone().Parent = v.PlayerGui
end
end)
If you would like,
You can create a remote event to update all players.
You can use :FireAllClients() to fire to all of the clients to that remote.
And so, it will update all of their playerlist.
I had issues with .PlayerAdded whilst in studio, but it is useable.
Unless if you don’t wanna mess with remotes then you can update a value like
local p = game:GetService("Players")
local players = p:GetChildren()
while wait(1) do
players = p:GetChildren()
end
Obviously that updating value thing is ineffective for this, and not good practice.
To test your code, you would have to publish it to a game and play the game, you cannot run it in studio because it won’t do anything since you are already in the game, but you can still try, as I said I had issues with it in studio.
I think I figured out the issue; turns out that if a player is higher than them on the player list (leaderstats, username) then their name will not be displayed for players who are lower that them. Why is this?