Pick a agent (for valorant in roblox)

Hi,
I want to make that you can pick your agent, like in valorant.

When you press a agent and on LOCK IN then that you pick a agent and no one else can pick him.

This is my code:

local plat = "TEST1"
local plat2 = "TEST2"

while true do
	wait(1)
script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Visible = false
	if game.Workspace:WaitForChild("TestC") then
		print("A player has picked ".. plat .. " (locked)") 
	elseif game.Workspace:WaitForChild("TestC2") then
		print("A player has picked ".. plat2 .. " (locked)") 
	end
	end)
end

~ Maini

3 Likes

Why are you wrapping your click event in a while loop? This isn’t needed.

Is this a server script or a local script?

1 Like

i want that the script check it every time if the player picks a agent (its a localscript)
TestC and TestC2 are the characters , they are in replicated storage and then when i press the character they are in workspace

You are creating a connection every second.

To add on, assuming this a local script you don’t want to allow the client to determine whether it can pick that character, you want the server.

Ask the questions, “can I pick this character?” rather than “I can/not pick this character”

If that’s the case, don’t use a while true loop. You’re making unneeded connections and the button is already listening once you call the event.

Even better, make a connection then disconnect it once you’re done.

local Connection = script.Parent.MouseButton1Down:Connect(function()
       —- Do stuff here
end)

Connection:Disconnect()

i want that the script check it every time if the player picks a agent (its a localscript)

I’m a bit confused. Is this for the agent itself, or for the lock in script. Please elaborate.

In Valorant when you pick a agent / character then the others in your team cant pick him, i want to make it like in valorant

I understand. I want to know which button you are programming because they both require different code:

the LOCK IN button, the button should check if one agent has “selected” (click on the button where you can select a agent) and then if you press the LOCK IN button you have picked the agent and no other from your team can pick him.

You could put the player inside a table with a remote event or function. From there you could make a code to have only 1 player in the table which is of course the selected agent.