Attribute "Changes", but Client and Server Does not See it

Hello, I’m trying to make a block system (Server Script) where if you are blocking you can’t attack. Therefore, I created an attribute in the script so I could detect if the player is blocking or not. But, whenever I change the attribute it doesn’t show in the script’s property. Even though when it prints out it says it’s been changed. Any idea why this might be happening? Is it a bug?

Here’s the script:

function Block(player)
	
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	
	local animator = humanoid:FindFirstChildOfClass("Animator")
	local Track = animator:LoadAnimation(script.Block)
	
	if not blocking then
		
		blocking = true
		
		print("Blocking", blocking) -- Prints true
		
		humanoid.WalkSpeed = 8
		
		Track:Play()
		
	elseif blocking then
		
		blocking = false
		
		print("Not Blocking", blocking) -- Prints false

		
		humanoid.WalkSpeed = 16
		
		Track:Stop()
		
	end
		
	if oldHealth == nil then
		oldHealth = humanoid.MaxHealth
	end
end

Here’s a video:

Thank you.

I’d recommend using a module script that has a table for blocking players and then using a function in said module script to check if the player is blocking or not and another function for adding/removing players from that table

1 Like

Pardon me but i do not see you utilizing any attribute function in this script (ie :GetAttribute(), :SetAttribute())? Is this the full script?

2 Likes

Have you animated the block animation in R6? If you have, make sure to set the track’s Priority to Action.

Also, where is block defined? I don’t see it.

And, as @TenBlocke and @TimeVector said, you should set the attribute with SetAttribute() instead.

1 Like

Also note that attributes are FE, so changes on the client do not replicate. You’ll have to do it server side, and as @TenBlocke mentioned, I don’t see a :SetAttribute() anywhere in your script.

2 Likes

Add this:

script:SetAttribute("blocking", true)

and:

script:SetAttribute("blocking", false)
1 Like