Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

textlabel is not always being updated for everyone?

Asked by 5 years ago
Edited 5 years ago

Hello, I'm trying to make a map vote system where multiple people can vote at the same time that limits each player to one vote and chooses the map with the most votes (the map choosing system is somewhere else in the script).

The problem is that; the textlabel doesnt update when there is more than one player trying to vote on the same thing or rather it does update but it doesnt update for other players until they vote on something else

I thought FireAllClients() handles this? Why isn't the textlabel updating for everyone?

I put comments explaining everything that needs to be explained in the scripts below (if the comments makes everything look confusing please tell me and ill remove them)

Local script

voteFrame.MapImage1.MouseButton1Click:Connect(function() 
--when player clicks on a imagebutton to vote
    if playerVote.Value == map1.Name then --if player is trying to vote for the same thing
        print("plr already voted for this")
    elseif playerVote.Value ~= map1.Name and playerVote.Value == map2.Name then 
        --if player's previous vote was map2 and not map1
        playerVote.Value = map1.Name --change their vote to map1
        --votenum1 is the total votes for map1 (is displayed on the textlabel)
        --votenum2 is the total votes for map2  (is displayed on the textlabel)
        --voteframe.mapimage1.mapname is the location of the textlabel for map1 (map2 is mapimage2.mapname)
        changeVoteEvent:FireServer("VoteNum1", "VoteNum2", voteFrame.MapImage1.MapName, voteFrame.MapImage2.MapName, map1.Name, map2.Name)
    elseif playerVote.Value ~= map1.Name and playerVote.Value == map3.Name then 
        --if player's previous vote was map3 and not map1
        playerVote.Value = map1.Name --change their vote to map1
        --votenum3 is the total votes for map3
        --mapimage3.mapname is the location of the textlabel
        changeVoteEvent:FireServer("VoteNum1", "VoteNum3", voteFrame.MapImage1.MapName, voteFrame.MapImage3.MapName, map1.Name, map3.Name)
    else
        playerVote.Value = map1.Name 
        --if the player didnt have a previous vote, change it to map1
        changeSingleVoteEvent:FireServer("VoteNum1", voteFrame.MapImage1.MapName, map1.Name)
    end
end)

Server script that handles the value changes and the text label changes

local function mapVoteEventFired(plr, target1, target2, text1, text2, map1, map2, otherValue, otherText, otherMap)
    --target1 is the value thats being added to
    --target2 is the value thats being subtracted from
    local target1 = script:FindFirstChild(target1) --finds the first value
    local target2 = script:FindFirstChild(target2) --finds the second value
    local otherValue = script:FindFirstChild(otherValue) --finds the third value (just to keep things updated)
    target1.Value = target1.Value + 1
    target2.Value = target2.Value - 1
    text1.Text = map1..": "..target1.Value
    text2.Text = map2..": "..target2.Value
    otherText.Text = otherMap..": "..otherValue.Value
end

local function mapSingleVoteEventFired(plr, target, text, map) 
    --does the same thing as the function above except it just changes 1 variable (if the player has no previous vote)
    local target = script:FindFirstChild(target)
    target.Value = target.Value + 1
    text.Text = map..": "..target.Value
end

changeSingleVoteEvent.OnServerEvent:Connect(mapSingleVoteEventFired)
changeVoteEvent.OnServerEvent:Connect(mapVoteEventFired)

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Make server change text label, not Player locally.

I mean you to forget FiringAllClients, you should just fire Server From Client Whenever Player Votes. Then Vote should be displayed by server in server script

0
still doesnt update for everyone Godlydeathdragon 227 — 5y
0
Sorry, is it in PlayerGui? GooierApollo664 183 — 5y
0
I know the issue GooierApollo664 183 — 5y
0
yea Godlydeathdragon 227 — 5y
View all comments (16 more)
0
I just want to know it better, it's not that simple GooierApollo664 183 — 5y
0
the parent of the values are in the server script (which is in serverscriptservice), and the local script is in the gui Godlydeathdragon 227 — 5y
0
I updated my scripts to show how my script looks now, got rid of FireAllClients and updated text label through the server, still doesnt work Godlydeathdragon 227 — 5y
0
Where is scripts located? GooierApollo664 183 — 5y
0
as i said previously, the server script is located in serverscriptservice, and the local script is in a screengui under startergui Godlydeathdragon 227 — 5y
0
you make sure that text label is active and Gui is enabled and things like that? cause everytime I thought I found mistake it turned out not to be mistake GooierApollo664 183 — 5y
0
you deleted some code and changed serverscript GooierApollo664 183 — 5y
0
yea, the code I deleted was the textlabel being changed on client, textlabel is now changed through server Godlydeathdragon 227 — 5y
0
also textlabel is active and gui is enabled, etc Godlydeathdragon 227 — 5y
0
still problem? GooierApollo664 183 — 5y
0
still problem? GooierApollo664 183 — 5y
0
yea it doesnt work still Godlydeathdragon 227 — 5y
0
can you elaborate at which exact point does it change and when it doesn't GooierApollo664 183 — 5y
0
what do you mean by "which exact point does it change and when it doesnt"? are u asking where the vote value changes and where textlabel is updated? if so, its in server script. local script exists to check if player clicked on the imagebutton and to check their previous vote and change it to their new vote Godlydeathdragon 227 — 5y
0
do you have a discord we can msg over? it'd be easier that way imo Godlydeathdragon 227 — 5y
0
yes I have discord, but if you are in server GooierApollo664 183 — 5y
Ad

Answer this question