#Voting system

1 messages · Page 1 of 1 (latest)

sudden hamlet
#

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.

fading marten
#

use playergui not startergui

lilac wadi
#

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.

sudden hamlet
sudden hamlet
#

can‘t be localplayer because it is a script not a local script

fading marten
#

can't be a script because ui interactions only occur on the client, so it must be a localscript.

sudden hamlet
fading marten
sudden hamlet
#

but I defenetly use a normal script rn and there localplayer doesn‘t exist

sudden hamlet
#

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?

fading marten
# sudden hamlet what is the diff between the 2?

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.

A container for a player's currently rendered Class.ScreenGui|ScreenGuis.

#

or in simpler terms, startergui is basically just a folder like replicatedstorage. only playergui actually functions as an actual gui.

sudden hamlet
#

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

fading marten
#

interactions only occur on the client.

sudden hamlet
fading marten
#

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.

sudden hamlet
fading marten
#

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

sudden hamlet
#

like that?

fading marten
#

if its something that should show on all player's playerguis, then you will need to detour through the server yes

sudden hamlet
#

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)

sick driftBOT
#

studio** You are now Level 4! **studio

sudden hamlet
#

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

fading marten
#

if you want to treat the text like a number you will need tonumber, yes

sudden hamlet
fading marten
#

roblox will coerce the number back to a string so you don't need tostring(), unless you are writing in --!strict mode

sudden hamlet
fading marten
#

;compile lua lua local x=tonumber("1a2b3c") print(x+1)

crisp tulipBOT
#
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 ?

fading marten
#

;compile lua lua local x=tonumber("123") print(x+1)

crisp tulipBOT
#
Program Output
124

sudden hamlet
fading marten
#

;compile lua lua local x="123" print(x+1) -- error; cannot perform arithmetic on a string

crisp tulipBOT
#
Program Output
124

fading marten
#

uwot

sudden hamlet
#

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

fading marten
#

i guess its a little inconsistent but you should still be strict about converting your strings to numbers when using them in math

fading marten
#

it is vanishingly unlikely there will ever be a mobile version of studio

sudden hamlet
#

adding and removing values. Life was so easy :c

fading marten
sudden hamlet
#

never thought like that

fading marten
#

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

sudden hamlet
sudden hamlet
fading marten
fading marten
#

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

fading marten
#

its a new tool in your toolbelt that you can use to solve other problems later

sudden hamlet
fading marten
#

getting good at any skill is the same ;p

#

no one starts out perfect

sudden hamlet
#

I‘ll just keep working on it. Ty for your help and motivation. Imma save that picture xD

#

I gotta „wake up“ in 6 hours and haven‘t even tried to sleep irlcry