Server scripts cant detect a players click on a GUI (I’m guessing that this is a server script)
Put “ReadyUp” in replicated storage.
Create a “RemoteEvent” name it “ReadyUpEvent” and place it in replicated storage
Create a “LocalScript” name it whatever you want and place it in “StarterPlayerScripts”
Create a “ServerScript” name it whatever you want and place it in “ServerScriptService”
Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReadyUpEvent = ReplicatedStorage:WaitForChild("ReadyUpEvent")
local Button = workspace.Button --Change this to your button
local IsReady = false
Button.Activated:Connect(function()
if IsReady then --if statements always check for anything True so you can just do this
ReadyUpEvent:FireServer(false)
else
ReadyUpEvent:FireServer(true) --Tells the server that you want to ready up
end
IsReady = not IsReady --Sets "IsReady to what its not (if IsReady = true then it'll make it false)"
end)
ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReadyUpValue = ReplicatedStorage:WaitForChild("ReadyUp")
local ReadyUpEvent = ReplicatedStorage:WaitForChild("ReadyUpEvent")
local ReadyGUI = workspace.ReadyGUI --Change this to your GUI
ReadyUpEvent.OnClientEvent:Connect(function(Player, IsReady)--Listen for the client
if IsReady then
ReadyUpValue.Value += 1 --Use += insted
else
ReadyUpValue.Value -= 1
end
end)
ReadyUpValue.Changed:Connect(function(Value)--Check when the value changes
ReadyGUI.Text = Value.."/4" --Set the text to this
end)
Why are you trying to use a second parameter in the PlayerRemoving event? PlayerRemoving only has 1 parameter and that is the player who left, you should place that script inside the script that counts the votes and then remove the vote through that script.
I’m gonna take the ServerScript that @Meb150828 gave you as an example and modify it so it fits your needs (ty beans btw):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReadyUpValue = {}
local ReadyUpNumber = ReplicatedStorage:WaitForChild("ReadyUp")
local ReadyUpEvent = ReplicatedStorage:WaitForChild("ReadyUpEvent")
local ReadyGUI = workspace.ReadyGUI --Change this to your GUI
ReadyUpEvent.OnServerEvent:Connect(function(Player, IsReady)--Listen for the client
if IsReady and not table.find(ReadyUpValue, player) then
table.insert(ReadyUpValue, player)
else
table.remove(ReadyUpValue, table.find(ReadyUpValue, player))
end
ReadyUpNumber.Value = #ReadyUpValue
end)
ReadyUpValue.Changed:Connect(function(Value)--Check when the value changes
ReadyGUI.Text = Value.."/4" --Set the text to this
end)
game.Players.PlayerRemoving:Connect(function(Player)
print("Player Left")
if table.find(ReadyUpValue, player) then
table.remove(ReadyUpValue, table.find(ReadyUpValue, player))
print("Removing 1")
end
ReadyUpNumber.Value = #ReadyUpValue
end)
In this script I created a table that shows every player who voted, and also a small type of anticheat that doesn’t allow the players to ready up like crazy. If a player leaves it gets taken out of that table and the Value updates.
If you want to clear the players who readied up, just do table.clear(ReadyUpValue) and ReadyUpNumber.Value = #ReadyUpValue.