Need help about simple script #3

Hello
I have a dummy that chases player.
Dummy model has an attribute called Target.
image
It changes to true if dummy has a target. (means dummy is chasing someone)
I want my script to change walkspeed if dummy has a target.

But script doesn't work
local chasing = script.Parent:GetAttribute("Target") 
chasing.Changed:Connect(function(newValue)
	if newValue == true then -- if has a target
		print("asd")
		script.Parent.Humanoid.WalkSpeed = 20 --change walkspeed
		end
		elseif newValue == false then --if doesn't have a target yet or lost the one
		print("dsa")
		script.Parent.Humanoid.WalkSpeed = 8 --change walkspeed back to deafult
	end
	end
end)

I’ve also tried GetAttributeChangedSignal but I can’t find the script right now.

Why does my script doesn’t work?
Thank you.

local chasing = script.Parent:GetAttribute("Target") 
chasing.Changed:Connect(function(newValue)
	if newValue == true then -- if has a target
		print("asd")
		script.Parent.Humanoid.WalkSpeed = 20 --change walkspeed
	elseif newValue == false then --if doesn't have a target yet or lost the one
		print("dsa")
		script.Parent.Humanoid.WalkSpeed = 8 --change walkspeed back to deafult
	end
end)
1 Like

thanks but that doesn’t work w

GetAttribute will return a bool and as such chasing will be a bool datatype which obviously does not have a changed event. To listen for when a specific attribute is changed use GetAttributeChangedSignal

local Dummy = script.Parent
Dummy:GetAttributeChangedSignal("Target"):Connect(function()
	if Dummy:GetAttribute("Target") then
		print("asd")
		Dummy.Humanoid.WalkSpeed = 20
	else
		print("dsa")
		Dummy.Humanoid.WalkSpeed = 8
	end
end)

P.S Changed only fires when Properties are changed, not Attributes. Use AttributeChanged