PlayerValue
Import Weave.PlayerValue from the Weave module.
1 2 | |
A Weave PlayerValue stores a value and updates for a specific player.
:getFor(player) and :setFor(player, newValue) from the Server.
ONLY :get() on the Client.
From the client can read from them with :get().
PlayerValue updates to a clientServer¶
local playerCash = PlayerValue.new("PlayerCash", 0)
function updateCash(player: Player, cash: number)
playerCash:getFor(player) --> 0
playerCash:setFor(player, cash)
playerCash:getFor(player) --> 1
end)
✨ PlayerValue updates to the client automatically ✨
Client¶
local playerCash = PlayerValue.new("PlayerCash")
playerCash:get() --> 1
Recommended Usage¶
Create a PlayerValue in ReplicatedStorage, so you can access it on Server and Client.
ReplicatedStorage¶
local Weave = require(ReplicatedStorage.Weave)
local PlayerValue = Weave.PlayerValue
return PlayerValue.new("PlayerCash", 0)
Server¶
On the Server, we can :get() and :set() the PlayerValue.
local playerCash = require(ReplicatedStorage.PlayerValues.PlayerCash)
function updateCash(player: Player, cash: number)
playerCash:getFor(player) --> 0
playerCash:setFor(player, cash)
playerCash:getFor(player) --> 1
end)
Client¶
On the Client, PlayerValue is just a Weave Value.
When :set() on the server, the Value is updated on the client.
We can use it like any other Value:
local playerCash = require(ReplicatedStorage.PlayerValues.PlayerCash)
Attach(ScreenGui.CashDisplay.TextLabel) {
Text = playerCash
}
playerCash.Changed:Connect(function()
print("PlayerCash updated by the server: " .. playerCash)
end)