#voting system won't work

1 messages · Page 1 of 1 (latest)

uncut ridge
#

Script for reference:


game:FindService("ReplicatedStorage").Vote.OnServerEvent:Connect(function(plr,notvoted,which) print("ayoo") -- this is where it fails
    local remote = game:FindService("ReplicatedStorage").Vote
    if notvoted then
        if which == 1 then
            remote:FireClient(plr,1,0)
        elseif which == 2 then
            remote:FireClient(plr,0,1)
        end
        lastvote = which
    else
        if which == 1 then
            if lastvote == 2 then
                remote:FireClient(plr,1,-1)
            end
        elseif which == 2 then
            if lastvote == 1 then
                remote:FireClient(plr,-1,1)
            end
        end
    end
end)```
jade pewter
#

take a ss instead pls

#

im suffering trying to read this

uncut ridge
jade pewter
#

and the local script?

#

also do you have a loading system?

#

i just looked into findservice and it might not be getting replicated storage due to it not being loaded yet

uncut ridge
uncut ridge
jade pewter
#

if you dont wanna do allat i think getservice should work fine

#

so just replace findservice with getservice

uncut ridge
jade pewter
#

maybe its the pressedchap == not 1

#

i never see anyone use not like that

#

just use ~= instead

#

also change the findservice in the localscript too

gritty scroll
#

local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Make sure the RemoteEvent exists
local remote = ReplicatedStorage:WaitForChild("Vote")

-- Dictionary to store last vote per player
local lastvote = {}

-- Vote count table (optional, if you want total tracking)
local voteCount = {
[1] = 0,
[2] = 0,
}

remote.OnServerEvent:Connect(function(plr, notvoted, which)
print("Vote received from:", plr.Name, "Vote option:", which)

if not lastvote[plr] then
    lastvote[plr] = 0
end

if notvoted then
    if which == 1 then
        voteCount[1] += 1
        remote:FireClient(plr, 1, 0)
    elseif which == 2 then
        voteCount[2] += 1
        remote:FireClient(plr, 0, 1)
    end
    lastvote[plr] = which
else
    if which == 1 and lastvote[plr] == 2 then
        voteCount[2] -= 1
        voteCount[1] += 1
        remote:FireClient(plr, 1, -1)
        lastvote[plr] = 1
    elseif which == 2 and lastvote[plr] == 1 then
        voteCount[1] -= 1
        voteCount[2] += 1
        remote:FireClient(plr, -1, 1)
        lastvote[plr] = 2
    end
end

end)

-- Clean up votes when player leaves
game.Players.PlayerRemoving:Connect(function(plr)
local old = lastvote[plr]
if old and voteCount[old] then
voteCount[old] -= 1
end
lastvote[plr] = nil
end)

#

@uncut ridge place it in serverscriptservices

jade pewter
#

wow

#

dont spoonfeed bruh

uncut ridge
#

what

#

wtf does that mean

#

this is a scriptin issue how is feeding anything to you related

jade pewter
#

its a phrase

uncut ridge
#

a silly phrase

#

;_;

gritty scroll
#

Try this

charred meadow
uncut ridge
charred meadow
# uncut ridge i dont really get how to do this but thx for the tip

just to make it easier to read in discord
Before:


game:FindService("ReplicatedStorage").Vote.OnServerEvent:Connect(function(plr,notvoted,which) print("ayoo") -- this is where it fails
    local remote = game:FindService("ReplicatedStorage").Vote
    if notvoted then
        if which == 1 then
            remote:FireClient(plr,1,0)
        elseif which == 2 then
            remote:FireClient(plr,0,1)
        end
        lastvote = which
    else
        if which == 1 then
            if lastvote == 2 then
                remote:FireClient(plr,1,-1)
            end
        elseif which == 2 then
            if lastvote == 1 then
                remote:FireClient(plr,-1,1)
            end
        end
    end
end)```

After:
```lua
local lastvote

game:FindService("ReplicatedStorage").Vote.OnServerEvent:Connect(function(plr,notvoted,which) print("ayoo") -- this is where it fails
    local remote = game:FindService("ReplicatedStorage").Vote
    if notvoted then
        if which == 1 then
            remote:FireClient(plr,1,0)
        elseif which == 2 then
            remote:FireClient(plr,0,1)
        end
        lastvote = which
    else
        if which == 1 then
            if lastvote == 2 then
                remote:FireClient(plr,1,-1)
            end
        elseif which == 2 then
            if lastvote == 1 then
                remote:FireClient(plr,-1,1)
            end
        end
    end
end)```
uncut ridge
#

so um

flint cometBOT
#

studio** You are now Level 12! **studio

uncut ridge
#

my discord doesnt actually have lua coloring

#

it reads it all the same grey

charred meadow
#

oh lol

#

it might still work for others tho

uncut ridge
#

btw

#

i jus discovered

#

it was sendig nil bc it reads remoteevents backwards

#

since it sent plr, 1 ,0 it received 0,1,plr and so on

#

crazy

#

i mean i just chwecked again