Ready Up System

im trying to make a ready up system

local readyup = false
local NORU = game:GetService("ServerStorage").ReadyUp.Value

script.Parent.MouseButton1Click:Connect(function()
	if readyup == false then
		NORU = NORU + 1
		readyup = true
		print("Ready Up")
		
	elseif readyup == true then
		NORU = NORU - 1
		readyup = false
		print("Not Ready")
	end
end)

NORU (Number Of Ready Ups) is a number value

i cant find a way to make the NORU show on a gui for everyone

and NORU value Doesnt Change For everyone its just local

i also cant find a way to make it where it decreases when they leave and it only decreases when the persons readyup and not when they are not

1 Like

First:
Don’t reference the Value as a Variable
Second:
Isn’t it mean to be only Local? The Server can’t see GUis

Server scripts cant detect a players click on a GUI (I’m guessing that this is a server script)

  1. Put “ReadyUp” in replicated storage.

  2. Create a “RemoteEvent” name it “ReadyUpEvent” and place it in replicated storage

  3. Create a “LocalScript” name it whatever you want and place it in “StarterPlayerScripts”

  4. 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)
2 Likes

it says “OnClientEvent can only be used on the client” in the server script

i think i fixed it with OnServerEvent

plrs.PlayerRemoving:Connect(function(Player, IsReady)
	print("Player Left")
	if IsReady then
		ReadyUpValue.Value -= 1
		print("Removing 1")
	end
end)

i then added this but it wont remove one when someone leaves

2 Likes

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.

how would i do that and im still new to scripting so i dont know much

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.

2 Likes

Sorry about that I meant to put “OnServerEvent”

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.