I’m working on a voting GUI, but I’m making it so you can’t vote yourself. Here is what I have so far:
for i,v in pairs(votePlayers) do
if v ~= game.Players.LocalPlayer then
local vButton = Instance.new("TextButton")
vButton.Text = v
vButton.Parent = votingGui.Frame
votingScript:Clone().Parent = vButton
else end
end
However, even when I run it, it will still display the local player. Is there anything that I’m doing wrong? Thank you in advance.
I realized my error; I’m not able to use game.Players.LocalPlayer in a ServerScript. However, I don’t want to turn it into a LocalScript because I don’t like using Local Scripts to control GUI.
Localscripts are primarily used to control UI or GUI elements in Roblox.
What are you talking about when you say you do not like using LocalScripts to control GUI?
Is there any particular reason why?
Yes, if that GUI is placed in PlayerGui. You can reference the player from here.
For example if the script was placed here:
You can reference the player by
I usually use ServerScripts to control GUI and when they appear on a player’s screen because I may do other serverwide functions with the same script. It’s a lot easier for me as I don’t have to do so much communication with the server. It’s a bit of a bad habit but it hasn’t caused me any major issue.
GUIs should only be controlled by local scripts. It’s not if you like or dislike it, it’s basically good practice, using server scripts can also affect performance.
It’s easier for you, but it’s harder for the players that play your game.
Why? Ping, anyone who has bad ping will not recieve something in time.
That is what you should use, don’t put unnecessary load on the Server, by letting it handle UI for every single Client, use a local script for that purpose.
Also, with ServerScripts and FE , the Server is obscure of the server-script’s existence when it is in PlayerGui thus that server script doesn’t work, unless this got changed
Use a localscript for UI unless you want a highly latent game, where UI respond in about 2 seconds to a command localscripts can execute in mere miliseconds.
This is a bad habit and yes, you don’t just write bad code because it benefits you as @VegetationBush mentioned.
Just call a remote event, they can still access that script since its in startergui and its not on a server. Hackers can easily exploit your game with that.
We are answering your question: Use a localscript, this gets the localPlayer nice and easy.
Also, being criticised is how people learn; be it a builder, animator, scripter.
Is this a table with all the players names in the server, when someone leaves remove that players name from the table. If you cant handle criticism then you cant be a scripter or a builder.
Technically, we did answer your question. We are telling you to utilize local scripts, which will solve your problem. Using a local script, this would be your answer:
On the Forum, it is a good habit for developers to give the best solution they know; what you’re doing is discouraged practice, @fredrick254 only suggested a good idea but it’s up to you to decide whether you want to follow it though.
You won’t face any problems owing to the fact that you’re not in a real environment where there’s going to be several players who’ll potentially interact with UI frequently.
In your code you wrote :
for i,v in pairs(votePlayers) do
-- change this to
for _, player in ipairs(votePlayers) do
because as I’ve mentioned in other threads too, ipairs is built to work with contiguous arrays with numerical indices, and will provide you a quicker result.
Also, GetService() methods are better than dot syntax for services, there’s guaranteed instantiation.
I can suggest you another way to do this; through a Local Script
A local script :
local Players = game:GetService("Players")
local votePlayers = ...
local currentPlayer = Players.LocalPlayer
if votePlayers[currentPlayer] then
i = table.find(votePlayers, currentPlayer)
table.remove(votePlayers, i)
else
print("Already absent from votePlayers")
end
for _, player in ipairs(votePlayers) do
local vButton = Instance.new("TextButton")
vButton.Text = player.Name
vButton.Parent = votingGui.Frame
end
However, if votePlayers contains names only, then go ahead with @TokoNanami’s solution.
I wanted to apologize for acting so inappropriately yesterday.
I need to be better with handling criticism and I’ll never grow as a developer (or a person) without understanding that I’ll have to change some things to become smarter and better.
Thank you to everyone who was giving me constructive feedback and for being honest. It means a lot. I’ll try to act smarter and less irrationally going forward and I’ll take this to heart.
It was wrong of me to discard this very useful feedback. My sincerest apologies.