#How could I manage multiple players' statuses without relying on client scripts?

10 messages · Page 1 of 1 (latest)

sage field
#

An example would be if a player's weapon is drawn out or not. If I were to write this on a server script, then all players would share the same weapon drawn status, and that wouldn't be good.
I do not want to write something like this on a client script since they're exploitable.

drowsy gust
#

you can do this in multiple ways! the simplest would probably be just a boolean value under the player's character that gets changed.

#

so, lets say you insert a boolean value object under the player's character. you can do this anytime the player's character loads like this:

game.Players.PlayerAdded:Connect(function(player)
  player.CharacterAdded:Connect(function(character)
    local newValue = Instance.new("BoolValue")
    newValue.Parent = character
    newValue.Value = false -- can be edited to true or false depending on what the current value is when the character loads, up to you!
  end)
end)
#

then, you just change that value whenever something happens, like in this case, when the player draws their weapon

#

and you can call that value and check the value (if it's true or false) whenever needed

#
-- player = the player with the value being changed; 
-- newValue = the new value (true or false in this case) that it's changed to
function ChangeBoolean(player, newValue)
  local boolVal = player.Character and player.Character:FindFirstChild("BoolValue")

  if boolVal then
    boolVal.Value = newValue
  end
end
#

the function above changes the boolean under the player's character to whatever value is provided

#
-- player = the player that the value is being grabbed from
function GetBoolean(player)
  local boolVal = player.Character and player.Character:FindFirstChild("BoolValue")

  return boolVal and boolVal.Value
end
#

the above returns the value you're trying to get (true or false depending on what it is in this case)

drowsy gust