So I’m learning about values (IntValue, BoolValue, CFrameValue, etc.) but then there’s this question that I couldn’t find in any tutorials: Can you change Values directly? I was wondering if you can change a BoolValue from a button, a remote event/function, or a Touched event. It would help if I would collect some answers!
Yep you can change a value with all those methods. It does also depend on where the certain value you want to change is though.
You can change a value in all those ways, but if you were to change it in a local script it only changes for you. If you were to change it in a script it changes for everyone.
Sure you can! That’s a very nice feature of values. For example, let’s take an IntValue. Everytime a RemoteEvent is fired, the value will go up by one. This is what the script would look like:
local IntValue = Instance.new("IntValue")
local remote = game:GetService("ReplicatedStorage").RemoteEvent
remote.OnServerEvent:Connect(function(plr)
IntValue.Value = IntValue.Value + 1
end)
*Note that the IntValue doesn’t have a parent and its value is changed on the server, aka it will change for everyone.
Yes, you can edit values directly. You would just have to change its Value
property through a script.
For example, let’s say you wanted to use a NumberValue
. You want to increase its value by 1 every time a button is clicked (for just the local player of course; see @Dolphin_Worm’s post for more information).
- Make your button, and insert a LocalScript.
- Put the
NumberValue
in ReplicatedStorage.
Inside of the LocalScript, your code would look something like this:
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- variable for ReplicatedStorage
local NumberValue = ReplicatedStorage.NumberValue -- variable for the NumberValue
local button = script.Parent -- variable for the button
button.MouseButton1Click:Connect(function() -- detecting when the button has been clicked
NumberValue.Value = NumberValue.Value + 1 -- incrementing the value of the NumberValue by 1
end)
so if I wanted to change a boolvalue from false to true, I should put:
local BoolValue = game.Replicated.BoolValue.Value
script.Parent.MouseButton1Down:Connect(function()
BoolValue = true --Makes the value true
end)
Your code block up there would cause BoolValue
to only inherit the value found within the .Value
property of game.Replicated.BoolValue
, not the object that holds said value. This causes the BoolValue
variable up there to give only the boolean by itself, and changing BoolValue
will not change game.Replicated.BoolValue.Value
It would make more sense to shorten the path so it ends at BoolValue
:
local Bool = game.Replicated.BoolValue
and then change the mouse button binding so it assigns to Bool.Value
.