If statement does not check changes

I am trying to make an attribute when set to true, the part removes when a player touches it.

but if I turn it on, it actually works, when I step on it, it is deleted.
but if I turn it off, and then on it does not work.

i tried this code:

local Part = script.Parent
local DOT = Part:GetAttribute("DisappearOnTouch")



while true do	
if DOT == true then
	script.Parent.Touched:Connect(function()
			script.Parent:Destroy()
		end)
end
end

Don’t do a loop for this. Instead, check if DOT is true when the part is touched.

local Part = script.Parent

script.Parent.Touched:Connect(function()
	if Part:GetAttribute("DisappearOnTouch") then
		script.Parent:Destroy()
	end
end)

To answer the question as to why your code wouldn’t work anyway, you’re setting the DOT variable to the attributes value. Meaning it won’t change if the attribute changes.

Oh, yeah good idea, i should check when the part is touched instead

no, i tested the script and did not work

I tested it and it does work. Are you setting the attribute properly?

1 Like

How are you changing the attribute so that when you check it’s got a different value?

Can we see how the attribute is set in Properties?

1 Like

name: DisappearOnTouch

= false it is set to false

I’m not really familiar with attributes, could you try just adding the DisappearOnTouch attribute without any value like false? That may be interfering with :GetAttribute though this may be very wrong as :GetAttribute only listens for the name and not the attribute’s value.

1 Like

tried this dint work

local Part = script.Parent

script.Parent.Touched:Connect(function()
if Part:GetAttribute(“DisappearOnTouch”) == true then
script.Parent:Destroy()
end
end)

That’s not what I meant, I meant if you could delete the value of the attribute.

what, why would i?
this topic is about the attribute, why would i

No, like, you have the name of the attribute, leave the other part blank. I’m banned from Roblox as of now so I can’t show you what I mean.
image
In this image, leave the space where you would put “75”, “32”, etc. blank. And try again.

1 Like

huh?
it is a boolean. and not a value

you are banned?
but i can see your roblox profile. how are you banned?

Banned for 7 days. Try another place, and try @ellienonekomimi’s script over there.

1 Like

of course i tried, it did not wwrok

Okay, first of all, where is the script located? Is it a regular script or a local script?

1 Like

yes, it is a server script.

server script means regular script.

his script does not work because did not mention a boolean