Hi There!
I have a voting system, but it’s suddenly stopped working!
The player can choose their vote, but then they can’t change it!
Server script:
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Events = ReplicatedStorage:WaitForChild('Events')
local Votes = ReplicatedStorage:WaitForChild('Votes')
local MPS = game:GetService('MarketplaceService')
Events.AddVote.OnServerInvoke = function(...)
local Args = {...}
local Player = Args[1]
local MapNumber = Args[2]
if Player and MapNumber then
local VoteToAdd = Votes:FindFirstChild('Map'..MapNumber)
if VoteToAdd ~= nil then
if not MPS:UserOwnsGamePassAsync(Player.UserId,11254132) then
VoteToAdd.Value += 1
else
VoteToAdd.Value += 2
end
if Player.MapVoted.Value ~= 0 then
local VoteToRemove = Votes:FindFirstChild('Map'..Player.MapVoted.Value)
if VoteToRemove ~= nil then
if not MPS:UserOwnsGamePassAsync(Player.UserId,11254132) then
VoteToAdd.Value -= 1
else
VoteToAdd.Value -= 2
end
else
return false
end
end
Player.MapVoted.Value = MapNumber
return true
else
return false
end
else
return false
end
end
game.ReplicatedStorage.Votes.Map1:GetPropertyChangedSignal('Value'):Connect(function()
workspace.NewLobby:WaitForChild('MapVoting',math.huge).Vote.Office.Vote.Text = 'Votes: '..game.ReplicatedStorage.Votes.Map1.Value
end)
game.ReplicatedStorage.Votes.Map2:GetPropertyChangedSignal('Value'):Connect(function()
workspace.NewLobby:WaitForChild('MapVoting',math.huge).Vote.Park.Vote.Text = 'Votes: '..game.ReplicatedStorage.Votes.Map2.Value
end)
game.ReplicatedStorage.Votes.Map3:GetPropertyChangedSignal('Value'):Connect(function()
workspace.NewLobby:WaitForChild('MapVoting',math.huge).Vote.Supermarket.Vote.Text = 'Votes: '..game.ReplicatedStorage.Votes.Map3.Value
end)
game.ReplicatedStorage.Events.ResetMapVoting.Event:Connect(function()
game.ReplicatedStorage.Events.ResetMapVotingClient:FireAllClients()
for Index, Player in pairs(game.Players:GetPlayers()) do
spawn(function()
Player.MapVoted.Value = 0
end)
end
for Index, Vote in pairs(game.ReplicatedStorage.Votes:GetChildren()) do
Vote.Value = 0
end
end)
Local Script:
local Player = game.Players.LocalPlayer
local CanVote = false
local HasVotedFor
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Events = ReplicatedStorage:WaitForChild('Events')
game.ReplicatedStorage.Events.ResetMapVotingClient.OnClientEvent:Connect(function()
CanVote = true
HasVotedFor = nil
end)
Events.DisableVoting.OnClientEvent:Connect(function()
CanVote = false
end)
workspace.NewLobby:WaitForChild('MapVoting',math.huge).Vote.Office.MouseButton1Click:Connect(function()
if HasVotedFor ~= 1 then
if CanVote == true then
HasVotedFor = 1
local AddVote = Events.AddVote:InvokeServer(1)
if AddVote then
print('successful!')
workspace.Success:Play()
else
workspace.Error:Play()
end
end
end
end)
workspace.NewLobby:WaitForChild('MapVoting',math.huge).Vote.Park.MouseButton1Click:Connect(function()
if HasVotedFor ~= 2 then
if CanVote == true then
HasVotedFor = 2
local AddVote = Events.AddVote:InvokeServer(2)
if AddVote then
workspace.Success:Play()
else
workspace.Error:Play()
end
end
end
end)
workspace.NewLobby:WaitForChild('MapVoting',math.huge).Vote.Supermarket.MouseButton1Click:Connect(function()
if HasVotedFor ~= 3 then
if CanVote == true then
HasVotedFor = 3
local AddVote = Events.AddVote:InvokeServer(3)
if AddVote then
workspace.Success:Play()
else
workspace.Error:Play()
end
end
end
end)
Interestingly enough, the success sound plays, but the votes don’t change!
I get no errors, thanks for any help!