"Already Playing" System

Hello!

I am currently working on an arcade game where players have access to play several different games.

I’d like to implement a system that checks if a player is already playing a game. For example, a player clicks a Gui, granting them access to a game. A variable is set to true, preventing them from trying to play multiple games. The variable is set to false upon finishing playing the game.

What would be the best approach to this? What type of variable would I use?

Thanks :slight_smile:

2 Likes

I think that you should create an attribute somewhere in the Player/Player’s Humanoid

Hard to tell you how to implement it without seeing what code you already have

Yeah the best way to do this is by either using a Boolean Value parented to the player that is set to “True” when a player is playing

script.Parent.MouseButton1Click:Connect(function()
    player.BoolValue.Value = true
end)

Or you could have an attribute in the players humanoid that is set to “True” when a player is playing

script.Parent.MouseButton1Click:Connect(function()
    player.character.Humanoid:SetAttribute("BoolValue.", true)
end)

How would I check what the player’s attribute is in a conditional statement? The code is in a ServerScript, so how would I get the player?

To find an attribute you need to go to the propertys tap and scroll all the way down to where it says “attributes” and then add one. but in your case you would need to create an atributte for every player that joins. try a script like this.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")

		-- Check if the attribute already exists just in case
		if humanoid:GetAttribute("MyBool") == nil then
			humanoid:SetAttribute("MyBool", false)
		end
	end)
end)

^^^^^^^^^^
this script goes in server script service and creates an attribute for every player that joins