Hello, I would like to know what I am doing wrong and if someone can help me
I am creating a voting system and I need to take the vote of each player by pressing the button and then the number of their vote is shown in the textlabel
local character = game.Workspace.Player
local player = game.Players:GetPlayerFromCharacter(character)
script.Parent.votere.OnServerEvent:Connect(function(player)
local votenumber = script.Parent.valvote.Value
votenumber = player+1
print(votenumber)
local text = script.Parent.TextLabel
text.Text = "vote number: "..tostring(votenumber)
end)
I would use tables for voting systems. What’re you doing here? Not sure if I’m wrong but I don’t think you can just do “+1” on a player instance.
I’m beyond confused for this part, you can’t get the local player from the server, nor does “Player” exist in workspace unless you made an object for it
local voted = {} -- table to hold the players who voted
script.Parent.votere.OnServerEvent:Connect(function(player)
if table.find(voted, player.UserId) then return end -- the player already voted
table.insert(voted, player.UserId) -- add the player to a table
local votenumber = script.Parent.valvote -- don't do ".Value" because it won't update anything
votenumber.Value += 1 -- bascially votenumber.Value = votenumber.Value + 1 but easier
print(votenumber.Value)
local text = script.Parent.TextLabel
text.Text = "vote number: "..tostring(votenumber.Value)
end)
The player variable was defined after that script so it will error, and you wouldn’t need the player variable above anyway since you used a remote event only to get the player (which might be a bad idea) there probably won’t be a player in your game with the username of “player”