I am making a movement system, and I want all my animations to be played in one local script. Problem is, I can’t seem to find a way to check if a bool variable is true or false from the local script which handles all animations. I have tried using Boolean Attributes and Boolean Values but they would never seem to change from false to true at all, even though it was working from my crouch script. The Boolean Value was parented to the crouch script and so was the Attribute.
So a local script does everything on the client. So if you change that BoolValue on the client (using a localscript), that value will not be replicated to the other clients.
I think this is your question? Else I don’t see a problem.
I know about values not being changed on a local script but I read a post saying Boolean Values can be changed if it is parented to something like a tool, or the character. Anyways all I am trying to do is make the value actually show the change so I can have an animation played.
local BoolValue = Instance.new("BoolValue", script.Parent) -- In the LocalPlayer.
BoolValue.Value = true
print(BoolValue.Value) -- Make sure you print the Value property, it is a common mistake.
--// Services
local ContextActionService = game:GetService("ContextActionService")
--// Variables
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character.Humanoid or Character:WaitForChild("Humanoid")
local CrouchSpeed = 8
local NormalSpeed = 16
local CrouchJump = 0
local NormalJump = 50
local Crouching = script:WaitForChild("Crouching").Value
--// Functions
local function Handler(Name, State, Object)
if Name == "Crouch" then
if State == Enum.UserInputState.Begin then
if Crouching == false then
Humanoid.WalkSpeed = CrouchSpeed
Humanoid.JumpPower = CrouchJump
Crouching = true
else
Humanoid.WalkSpeed = NormalSpeed
Humanoid.JumpPower = NormalJump
Crouching = false
end
end
end
end
--// Binding
ContextActionService:BindAction("Crouch", Handler, true, Enum.KeyCode.C)
This is my Animation Handler Script:
--// Variables
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Script = Character:WaitForChild("MovementScripts", math.huge):WaitForChild("ToggledCrouch", math.huge)
local BoolValue = Script:WaitForChild("Crouching", math.huge)
while true do
print(BoolValue.Value)
task.wait(1)
end
The Crouch Script works as intended but the animation handler script doesn’t show the Boolean Value being changed.
You’re calling this wrong or the bool is in a place that is the sever not the client. Hard to say as you show no examples or file hierarchy. The other thing that comes to mind is you may not be waiting long enough for the bool to be ready. Try adding a local bool = where ever it is:WaitforChild(“the bool”)
local Crouching = script:WaitForChild("Crouching").Value, this is either true, or false. So a bool. Crouching = true, will make the boolean true, but not the Value property of the BoolValue.
Doesn’t mean it is totally there yet. Try adding a:
local humanoid = Character:WaitForChild(“Humanoid”)
Just to make sure the player is totally loaded …
So what you did is you signed variable Crouching to the Value property from the BoolValue. That Value from the BoolValue is a boolean, either true or false. So what you are doing is you are sigining Crouching to a boolean, as Value is a boolean.
Yeah, so Value is the property of the BoolValue, like Name is a property of a BoolValue as well. When you do BoolValue.Value you use that value.
local Value = BoolValue.Value -- true or false.
local Name = BoolValue.Name -- The name of the BoolValue.
print(Value) -- true or false.
print(BoolValue) -- The BoolValue.
if BoolValue then
-- The BoolValue exists.
end
if BoolValue.Value then
-- The BoolValue's Value property is true.
end
That is exactly why you use the documentation for everything.