Hello, I am making a mode voting for my game and got the script shown in the picture. I tested the tables. They are fine. But my function does nothing. I want to change a Textlabels text to 1,2,3 etc. deepending on how many votes it got meaning I find the matching "Counter" for the "Buttons" so i = 1 is the textlable and the button and they are together. So if you click Buttons [1] I want Counters[1] to show a number or better said. Change their text to text +=1 but as I said, clicking the buttons just does nothing. No errors, no printing.
#Voting system
1 messages · Page 1 of 1 (latest)
use playergui not startergui
Maybe let server handle the information. Do this on the client (use playergui) use remoteEvents to fire it to the server to get that information and fire it back to all clients. Im not an expert but this works for me. I explain it very short tho, let me know if you need further help.
I tried that and it didn‘t work. But I think I maybe used it wrong. How would you acces it (and which line)
localplayer.playergui
Nope
can‘t be localplayer because it is a script not a local script
nope
can't be a script because ui interactions only occur on the client, so it must be a localscript.
maybe that is the problem then
part of the problem, yes. using startergui instead of playergui is the other part.
but I defenetly use a normal script rn and there localplayer doesn‘t exist
I had exactly that explanation somewhere else back a few weeks. Why does that matter?
what is the diff between the 2?
Someone explained it to me but I just didn‘t understand it. He said like you basically don‘t use startergui in scripts and always use playergui because startergui is only the place to store it. Is that right like this?
https://create.roblox.com/docs/reference/engine/classes/StarterGui
When a Player.Character spawns, the contents of their PlayerGui (if any) are emptied. Children of the StarterGui are then copied along with their descendants into the PlayerGui.
--> https://create.roblox.com/docs/reference/engine/classes/PlayerGui
PlayerGui is a container that holds a player's UI. If a ScreenGui is a descendant, then any GuiObject inside of the ScreenGui will be drawn to the player's screen. Any LocalScript will also run if it is inserted into a PlayerGui.
or in simpler terms, startergui is basically just a folder like replicatedstorage. only playergui actually functions as an actual gui.
And why a local script? My idea in my head was: I have a text. That text should be changed for everyone. So the server has to change it :/… SCRIPT BETTER
interactions only occur on the client.
so startergui is basically a store and you acces it with playergui in a script?
you can mess with a player's playergui from the server like changing a textlabel's text, but you cannot connect to button clicks and other interactions.
so I‘d need 2 scripts flr it to work? One for the button - the button fires a remote - the event fires a script which changes the text?
it's the same situation as how you cannot get a player's mouse ray from the server, its only available on the client and you have to send it to the server using remotes if you want to use it on the server
like that?
that's one way to do it
if its something that should show on all player's playerguis, then you will need to detour through the server yes
So I have like a function: Button.Activated:FireOnServerEvent blah blah blah
and then a script: local textlable
change text to blah blah blah (get the text, turn it to a number, add 1, change it to a string)
** You are now Level 4! **
because rn the text is 0. If I turn that into a number with tonumber it should be 0 and if I add 1 and use tostring I can make 1 the text of the textlabel, right?
cause I never used tonimber/string thatway
if you want to treat the text like a number you will need tonumber, yes
but if I have 0 and say tonumber, I also get 0 as a number, right?
roblox will coerce the number back to a string so you don't need tostring(), unless you are writing in --!strict mode
I think it is easier to understand
;compile lua lua local x=tonumber("1a2b3c") print(x+1)
Program Output
/opt/wandbox/lua-5.4.7/bin/lua: prog.lua:2: attempt to perform arithmetic on a nil value (local 'x')
stack traceback:
prog.lua:2: in main chunk
[C]: in ?
.pyrofire | lua | lua-5.4.7 | wandbox.org
;compile lua lua local x=tonumber("123") print(x+1)
Program Output
124
.pyrofire | lua | lua-5.4.7 | wandbox.org
I sadly can‘t use studio for a while cause I am not at home but I‘ll try that in an online compiler
;compile lua lua local x="123" print(x+1) -- error; cannot perform arithmetic on a string
Program Output
124
.pyrofire | lua | lua-5.4.7 | wandbox.org
uwot
or is there a mobile version for apple?
I just heard there WILL be a mobile version for studio but Idk if it exists yet
i guess its a little inconsistent but you should still be strict about converting your strings to numbers when using them in math
idk what you mean but here's an online luau compiler https://luau.org/demo
it is vanishingly unlikely there will ever be a mobile version of studio
awww I remember that lil guy. I made my first shop in there
adding and removing values. Life was so easy :c
it was never easy. you were just ignorant to the things you now know which you didn't know before.
actually that sounds weird but makes much sense!
never thought like that
all that means is you're improving and you now know more about how much there is to know, and how much you don't know
so the mlre problems I have, the more I improve because only new things make problems?
I am 3-4 rn
something like, when you solve a problem once, you never need to solve it again and you will remember what to look for
playergui/startergui… xD
meanwhile if you don't solve your own problems and have someone else do it, like chatgpt, people giving you free code etc, thats why you learn nothing from that
yeah you now have a better understanding of that and will likely remember that
its a new tool in your toolbelt that you can use to solve other problems later
this is why instead of asking people to modify my script so it works, I talk like with you rn when I have a question
