Hi, I tried putting a bool check so if set to false cannot crouch, if set to true, can crouch.
But I cannot crouch even the bool value if it’s set to true or false
Here’s the crouch script
task.wait(1)
local TweenService = game:GetService("TweenService")
local tweenPart = game.Players.LocalPlayer.Character.Humanoid
local canCrouch = game.ReplicatedStorage.Values.canCrouch
local info = TweenInfo.new(
0.325,
Enum.EasingStyle.Back,
Enum.EasingDirection.Out,
0,
false,
0
)
local Goals = {
CameraOffset = Vector3.new(0,-1.5,0),
}
local info2 = TweenInfo.new(
0.3,
Enum.EasingStyle.Back,
Enum.EasingDirection.Out,
0,
false,
0
)
local Goals2 = {
CameraOffset = Vector3.new(0,0,0),
}
local PartTween = TweenService:Create(tweenPart, info, Goals)
local PartTween2 = TweenService:Create(tweenPart, info2, Goals2)
local animidle = tweenPart:LoadAnimation(script.Parent.Idle)
local animwalk = tweenPart:LoadAnimation(script.Parent.Walk)
local crouching = false
local waiting = false
local userinputservice = game:GetService("UserInputService")
userinputservice.InputBegan:Connect(function(input)
canCrouch:GetPropertyChangedSignal("Value"):Connect(function()
if input.KeyCode == Enum.KeyCode.LeftControl then
if waiting == false then
if crouching == false then
if canCrouch == true then
script.Parent.ImageColor3 = Color3.new(1, 1, 1)
script.Parent.Parent.ImageColor3 = Color3.new(0, 0.666667, 1)
tweenPart.WalkSpeed = 8
waiting = true
crouching = true
animidle:Play()
PartTween:Play() --plays it
tweenPart.Running:Connect(function(Speed)
if crouching == true then
if Speed >= 1 then
animidle:Stop()
if animwalk.IsPlaying == false then
animwalk:Play()
end
else
animidle:Play()
animwalk:Stop()
end
end
end)
task.wait(0.05)
waiting = false
else
script.Parent.ImageColor3 = Color3.new(0, 0, 0)
script.Parent.Parent.ImageColor3 = Color3.fromRGB(135, 135, 135)
tweenPart.WalkSpeed = 16
waiting = true
crouching = false
animidle:Stop()
animwalk:Stop()
PartTween2:Play()
task.wait(0.05)
waiting = false
end
end
end
end
if input.KeyCode == Enum.KeyCode.LeftShift then
if waiting == false then
if crouching == false then
if canCrouch == true then
script.Parent.ImageColor3 = Color3.new(1, 1, 1)
script.Parent.Parent.ImageColor3 = Color3.new(0, 0.666667, 1)
tweenPart.WalkSpeed = 8
waiting = true
crouching = true
animidle:Play()
PartTween:Play() --plays it
tweenPart.Running:Connect(function(Speed)
if crouching == true then
if Speed >= 1 then
animidle:Stop()
if animwalk.IsPlaying == false then
animwalk:Play()
end
else
animidle:Play()
animwalk:Stop()
end
end
end)
task.wait(0.05)
waiting = false
else
script.Parent.ImageColor3 = Color3.new(0, 0, 0)
script.Parent.Parent.ImageColor3 = Color3.fromRGB(135, 135, 135)
tweenPart.WalkSpeed = 16
waiting = true
crouching = false
animidle:Stop()
animwalk:Stop()
PartTween2:Play()
task.wait(0.05)
waiting = false
end
end
end
end
end)
end)
script.Parent.MouseButton1Click:Connect(function()
canCrouch:GetPropertyChangedSignal("Value"):Connect(function()
if waiting == false then
if crouching == false then
if canCrouch == true then
script.Parent.ImageColor3 = Color3.new(1, 1, 1)
script.Parent.Parent.ImageColor3 = Color3.new(0, 0.666667, 1)
tweenPart.WalkSpeed = 8
waiting = true
crouching = true
animidle:Play()
PartTween:Play() --plays it
tweenPart.Running:Connect(function(Speed)
if crouching == true then
if Speed >= 1 then
animidle:Stop()
if animwalk.IsPlaying == false then
animwalk:Play()
end
else
animidle:Play()
animwalk:Stop()
end
end
end)
task.wait(0.05)
waiting = false
else
script.Parent.ImageColor3 = Color3.new(0, 0, 0)
script.Parent.Parent.ImageColor3 = Color3.fromRGB(135, 135, 135)
tweenPart.WalkSpeed = 16
waiting = true
crouching = false
animidle:Stop()
animwalk:Stop()
PartTween2:Play()
task.wait(0.05)
waiting = false
end
end
end
end)
end)
canCrouch:GetPropertyChangedSignal("Value"):Connect(function()
if crouching == true and canCrouch == false then
crouching = false
end
end)
Help would be appreciated.