Change Variable for one Player

If i make something like this:

local a = false

game.ReplicatedStorage:WaitForChild("AA").OnServerEvent:Connect(function(player)

a = true

end)

Will that change the a to true for every Player or just for the Player who fires the Remote Event? Or Should i make the local a inside the Function? Thanks!

Yes it does as long as it’s in a server script!

1 Like

Since this is a server script it is shared by all clients and thus assigning ‘true’ to ‘a’ will result in ‘a’ pointing/referring to ‘true’ for every client.

So its true for every other Players already who sends a Remote Event?

Basically what you did was made the value true for everybody in the whole server

And when i do this:

game.ReplicatedStorage:WaitForChild("AA").OnServerEvent:Connect(function(player)

local a = false

a = true

end)

It is the Same?

No it is not the same, you are putting variable a inside of a different scope. Sure a is unique now but after that event is finished, it will be deleted. If you want to have a unique variable for each player, create a dictionary at a higher scope so it could be accessed anywhere in the script, then inside of the remote event, store the player as the key and set it to true. Here’s an example of what I mean.

example:

local List = {}
game.ReplicatedStorage:WaitForChild("AA").OnServerEvent:Connect(function(player)
   List[player] = true
end)

--- somewhere else.

if List[RandomPlayer] then
   print(List[RandomPlayer])
else
   print(false)
end

I basically check if a player is listed inside of the dictionary, if they are then print whatever is stored (which is true in this case), else then print false as they have not fired that remote event.

1 Like