Is there a way I can store a player in an object?

Basically I need to save a player value outside of a script so multiple other scripts can view it
Is there a way I can do that?

Yeah. Create a value in workspace or something and as long as you don’t change it with a local script it should work.

Which type of value should I use?

Depends. If you’re checking if the player did something like grabbed a key card without it being a tool, you can create a “boolvalue” and if it’s a number, create an “IntValue”

Oh wait that came out wrong
I need to store the player itself as an anticheat measure

An if statement for a bool:

if workspace.BoolValue.Value == true then

Wait what? What do you mean? Charrr

You can use an ObjectValue.

Same player value as what a localscript sends when you send a Remote Event (although I guess character works too)

_G.Player = -- the player

Other scripts can access the Player using _G.Player

print(_G.Player) -- prints the Player
1 Like
local clickdetector = script.Parent.ClickDetector
local Players = game:GetService("Players")
local CurrentPlayer = _G.CurrentPlayer1 -- Set to nil by another script (no it isn't looping)
clickdetector.MouseClick:Connect(function(player)
	if CurrentPlayer == nil then
		-- Do stuff
		CurrentPlayer = player
	else
		print("There is already an active player")
	end
end)

This is the script that I’ve come up with to use that method (I tried the ObjectValue method but it did the same thing)
If I print CurrentPlayer after setting it, it prints the player, but all other scripts print nil even after the change

What you’re doing is changing the variable CurrentPlayer, not _G.CurrentPlayer1. I’m pretty sure CurrentPlayer doesn’t make a reference to it, but instead just copies the value of _G.CurrentPlayer1. Change the code to this:

local clickdetector = script.Parent.ClickDetector
local Players = game:GetService("Players")
clickdetector.MouseClick:Connect(function(player)
	if _G.CurrentPlayer1 == nil then
		-- Do stuff
		_G.CurrentPlayer1 = player
	else
		print("There is already an active player")
	end
end)