Bool Attribute is returning true only

So when I try checking if the attribute bool value is false or true
but when I set the value to false it still returns true
here’s the script

player:GetAttributeChangedSignal("canCrouch"):Connect(function()
	if canCrouch then
		script.Parent.Crouch.Visible = true
		print(canCrouch)
	else
		print(canCrouch)
		script.Parent.Crouch.Visible = false
	end
end)

1 Like

where are you changing the value of the attribute ‘canCrouch’?

1 Like

i tried changing attribute bool value inside the player ingame in the explorer tab.

did you change to server before setting it?

Try this :

player:GetAttributeChangedSignal("canCrouch"):Connect(function()
	if canCrouch then
		script.Parent.Crouch.Visible = true
		print(canCrouch)
	else
		script.Parent.Crouch.Visible = false
        print(canCrouch)
	end
end)

I hope that was helpful ! :grin:

1 Like

oh right, he’s printing it before. Im stupid

1 Like

it’s still printing true?
(30 ch)

No, because you misplaced the print() !:grinning:
try ! :wink:

but the image button is still visible.

1 Like

Can you show us the hierarchy and all your codes related to it ? :thinking:

1 Like

the code is in one script
(THIS IS A PIGGY FANGAME)

task.wait(1)
local player = game.Players.LocalPlayer
local StartPlayerScare = game.ReplicatedStorage.Remotes:WaitForChild("StartPlayerScare")
local StopPlayerScare = game.ReplicatedStorage.Remotes:WaitForChild("StopPlayerScare")
local TweenWokenMessage = game:GetService("ReplicatedStorage").Remotes.TweenWokenMessage
local TweenMessage = game:GetService("ReplicatedStorage").Remotes.TweenMessage
local HeartBeat = script:WaitForChild("HeartBeat")
local Camera = workspace.CurrentCamera
local canCrouch = player:GetAttribute("canCrouch")

local DeathMessages = {
	[1] = "You shouldn't have messed",
	[2] = "You abbiden his orders",
	[3] = "You died"
	
}
local WokenMessages = {
	[1] = "He has woken up! (?)",
	[2] = "He is searching for you. (?)",
	[3] = "He has eyes on you. (?)"
}


local CameraShakerModule = require(game:GetService("ReplicatedStorage").Modules.CameraShaker)
local camShake = CameraShakerModule.new(Enum.RenderPriority.Camera.Value, function(shakeCFrame)
	workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * shakeCFrame
end)

local walk = 14
local run = 24

local power = 100
local sprinting = false


local character = player.Character or player.CharacterAdded:Wait()

local Animator = character.Humanoid:FindFirstChild("Animator")
local Run = Animator:LoadAnimation(script.Run)


local TweenService = game:GetService("TweenService")
local tweenPart = game.Players.LocalPlayer.Character.Humanoid
local canCrouch = true

local mobileSprintingState = false

local info = TweenInfo.new(
    0.325,          
    Enum.EasingStyle.Back,     
    Enum.EasingDirection.Out,    
    0,                    
    false,                
    0                      
)

local Goals = {             
    CameraOffset = Vector3.new(0,-0.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.Idle)

local animwalk = tweenPart:LoadAnimation(script.Walk)

local crouching = false
local waiting = false

local userinputservice = game:GetService("UserInputService")

if userinputservice.TouchEnabled then
	script.Parent.Crouch.DeviceImage.Visible = false
	script.Parent.Crouch.DeviceInfoMobile.Visible = true
elseif userinputservice.GamepadEnabled then
	script.Parent.Crouch.DeviceImage.Image = "rbxassetid://3202649268"
end

game.StarterGui:SetCoreGuiEnabled("Health", false)

userinputservice.InputBegan:Connect(function(input, gameProcessed)
	if canCrouch == true and gameProcessed == false then
    if input.KeyCode == Enum.KeyCode.LeftControl then
		if waiting == false then
			
				
				if crouching == false then
					sprinting = false
					
				script.Parent.Crouch.ImageButton.ImageColor3 = Color3.new(1, 1, 1)
				script.Parent.Crouch.ImageColor3 = Color3.new(0, 0.666667, 1)
					tweenPart.WalkSpeed = 8
					character.Humanoid.HipHeight = -2
                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)
                wait(0.05)
                waiting = false
					else
						
				script.Parent.Crouch.ImageButton.ImageColor3 = Color3.new(0, 0, 0)
					script.Parent.Crouch.ImageColor3 = Color3.fromRGB(135, 135, 135)
					character.Humanoid.HipHeight = 0
                tweenPart.WalkSpeed = 14
						waiting = true
						
                crouching = false
                animidle:Stop()
                animwalk:Stop()
                PartTween2:Play()
                wait(0.05)
                waiting = false
					end
					
				end
				
			end	
			
		end

	
	if input.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
		if canCrouch == true then
        if waiting == false then
				if crouching == false then
					
						
					
					sprinting = false
					script.Parent.Crouch.ImageButton.ImageColor3 = Color3.new(1, 1, 1)
					script.Parent.Crouch.ImageColor3 = Color3.new(0, 0.666667, 1)
					character.Humanoid.HipHeight = -2
                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)
                wait(0.05)
                waiting = false
						
					else
						
						
				script.Parent.Crouch.ImageButton.ImageColor3 = Color3.new(0, 0, 0)
				script.Parent.Crouch.ImageColor3 = Color3.fromRGB(135, 135, 135)
					tweenPart.WalkSpeed = 14
					character.Humanoid.HipHeight = 0
                waiting = true
                crouching = false
                animidle:Stop()
                animwalk:Stop()
                PartTween2:Play()
                wait(0.05)
                waiting = false
            end
				end
			end
			

		end
	
end)
script.Parent.Crouch.ImageButton.MouseButton1Click:Connect(function()
	if canCrouch == true then
		if waiting == false then
			if crouching == false then



				sprinting = false
				script.Parent.Crouch.ImageButton.ImageColor3 = Color3.new(1, 1, 1)
				script.Parent.Crouch.ImageColor3 = Color3.new(0, 0.666667, 1)
				character.Humanoid.HipHeight = -2
				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)
				wait(0.05)
				waiting = false

			else


				script.Parent.Crouch.ImageButton.ImageColor3 = Color3.new(0, 0, 0)
				script.Parent.Crouch.ImageColor3 = Color3.fromRGB(135, 135, 135)
				tweenPart.WalkSpeed = 14
				character.Humanoid.HipHeight = 0
				waiting = true
				crouching = false
				animidle:Stop()
				animwalk:Stop()
				PartTween2:Play()
				wait(0.05)
				waiting = false
			end
		end
	end
end)

userinputservice.InputBegan:Connect(function(input, gameProcessed)
	if canCrouch == true and gameProcessed == false then
		if input.KeyCode == Enum.KeyCode.ButtonB then
			if waiting == false then


				if crouching == false then
					sprinting = false

					script.Parent.Crouch.ImageButton.ImageColor3 = Color3.new(1, 1, 1)
					script.Parent.Crouch.ImageColor3 = Color3.new(0, 0.666667, 1)
					tweenPart.WalkSpeed = 8
					character.Humanoid.HipHeight = -2
					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)
					wait(0.05)
					waiting = false
				else

					script.Parent.Crouch.ImageButton.ImageColor3 = Color3.new(0, 0, 0)
					script.Parent.Crouch.ImageColor3 = Color3.fromRGB(135, 135, 135)
					character.Humanoid.HipHeight = 0
					tweenPart.WalkSpeed = 14
					waiting = true

					crouching = false
					animidle:Stop()
					animwalk:Stop()
					PartTween2:Play()
					wait(0.05)
					waiting = false
				end

			end

		end	

	end
	
	end)

-----------------------------

function UnCrouch()

	script.Parent.Crouch.ImageButton.ImageColor3 = Color3.new(0, 0, 0)
	script.Parent.Crouch.ImageColor3 = Color3.fromRGB(135, 135, 135)
	tweenPart.WalkSpeed = 14
	character.Humanoid.HipHeight = 0
	waiting = true

	crouching = false
	animidle:Stop()
	animwalk:Stop()
	PartTween2:Play()
	wait(0.05)
	waiting = false
end

local StartTween = TweenService:Create(Camera, TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.InOut), {FieldOfView = 90})
local StopTween = TweenService:Create(Camera, TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.InOut), {FieldOfView = 70})
local ShowBlood = TweenService:Create(script.Parent.Parent:WaitForChild("BloodScreen").Blood, TweenInfo.new(0.6), {ImageTransparency = 0})
local HideBlood = TweenService:Create(script.Parent.Parent:WaitForChild("BloodScreen").Blood, TweenInfo.new(0.6), {ImageTransparency = 1})

StartPlayerScare.OnClientEvent:Connect(function()
	ShowBlood:Play()
	StartTween:Play()
	HeartBeat:Play() 
end)


StopPlayerScare.OnClientEvent:Connect(function()
	HideBlood:Play()
	StopTween:Play()
	HeartBeat:Stop()
end)


TweenWokenMessage.OnClientEvent:Connect(function()
	script.Parent.InfoLabel.Text = WokenMessages[math.random(1, #WokenMessages)]
	local Show = TweenService:Create(script.Parent.InfoLabel, TweenInfo.new(0.3), {TextTransparency = 0})
	local Hide = TweenService:Create(script.Parent.InfoLabel, TweenInfo.new(1), {TextTransparency = 1})
	script.Alarm:Play()
	Show:Play()
	task.wait(2)
	Hide:Play()
end)

TweenMessage.OnClientEvent:Connect(function(message)
	script.Parent.InfoLabel.Text = message
	local Show = TweenService:Create(script.Parent.InfoLabel, TweenInfo.new(1), {TextTransparency = 0})
	local Hide = TweenService:Create(script.Parent.InfoLabel, TweenInfo.new(1), {TextTransparency = 1})

	Show:Play()
	wait(1)
	Hide:Play()
end)

game:GetService("ReplicatedStorage").Remotes.CameraShake.OnClientEvent:Connect(function()
	camShake:Start()
	camShake:Shake(CameraShakerModule.Presets.Explosion)
end)

--[[Advanced Resolution Scaling (EXPERIMENTAL ONLY!)

player:WaitForChild("PlayerGui").DescendantAdded:Connect(function(gui)
	if gui:IsA("GuiButton") then
		gui.Size = UDim2.new(Camera.ViewportSize.X / gui.Size.X, 0, Camera.ViewportSize.Y / gui.Size.Y, 0)
		print(gui.Name, gui.Size.X, gui.Size.Y)
	end
end)

Camera.Changed:Connect(function(value)
	for i, v in ipairs(player:WaitForChild("PlayerGui"):GetDescendants()) do
		if v:IsA("GuiButton") and v:IsA("Frame") then
			v.Size = UDim2.new(Camera.ViewportSize.X / v.Size.X, 0, Camera.ViewportSize.Y / v.Size.Y, 0)
			print(gui.Name, gui.Size.X, gui.Size.Y)
		end
	end
end)

--]]

player:GetAttributeChangedSignal("canCrouch"):Connect(function()
	if canCrouch then
		script.Parent.Crouch.Visible = true
	else
		script.Parent.Crouch.Visible = false
	end
end)
1 Like

Can I see the hierarchy of your button image ? :thinking:
EDIT : and its description (of crouch)

image

1 Like

Try this :

player:GetAttributeChangedSignal("canCrouch"):Connect(function()
	if canCrouch then
		script.Parent.Crouch.ImageButton.Visible = true
	else
		script.Parent.Crouch.ImageButton.Visible = false
	end
end)

it’s still doesnt work, also i need to hide script.Parent.Crouch because it hides the entire crouch frame.

1 Like

Maybe that ? :sweat_smile:

player:GetAttributeChangedSignal("canCrouch"):Connect(function()
	if canCrouch then
		game.StarterGui.Crouch = true
	else
		game.StarterGui.Crouch = false
	end
end)

ik that isn’t going work. StarterGui justs clones the children and put them to PlayerGui.

1 Like

I’m really lost because your script should work! :sweat_smile::face_with_raised_eyebrow:

im going to change the script tommorow later.

1 Like

the problem is that your canCrouch in if canCrouch then isn’t the attribute. try

player:GetAttributeChangedSignal("canCrouch"):Connect(function()
    canCrouch = player:GetAttribute("canCrouch")
    game.StarterGui.Crouch.Visible = canCrouch
end)

I don’t believe you’re actually changing your canCrouch variable anywhere, the attribute does not update a script’s variable.