Script not working

Trying to make a purchase and equip system and this textlabel script is not working:

local player = game:GetService("Players").LocalPlayer
while wait(.1) do
	if player:WaitForChild(script.Parent.Parent.Parent.Name).Value == true then
		local Cash = math.floor(script.Parent.Parent.Parent.Price.Value)

		local IsType = (function (T)
			T = tostring(T)
			return T:reverse():gsub("%d%d%d", "%1,"):reverse():gsub("^,", "")
		end)

		script.Parent.Text = "$" .. IsType(Cash)
	elseif player:WaitForChild(script.Parent.Parent.Parent.Name).Value == false then
		if player:WaitForChild("Hat").Value == script.Parent.Parent.Parent.Name then
			script.Parent.Text = "Equipped"

		else
			script.Parent.Text = "Equip"

		end
	end
end

image
the script CostumeInator clones the contents and adds them to hats in a folder

what error sended you? in the output

no errors were in the output at all, almost as if it’s refusing to function.

Is this code from the LocalScript selected, or the CostumeInator?

yes exactly what? we must know

Its from the localscript selected

why script.Parent.Parent.Parent.Name?
It’s like putting player:WaitForChild(“CostumeInator”)

image
TrenchCoat is one of the hats
TrenchCoat is also one of the player values

Can you replace WaitForChild to FindFirstChild?

Yes but that’s probably not the issue, WaitForChild is probably a better option.
Also, player:WaitForChild(script.Parent.Parent.Parent.Name) is there because the parent changes to TrenchCoat

In the image TrenchCoat is a 3d model.
In a 3d model, there are not Property called Value?

player:FindFirstChild(script.Parent.Parent.Parent.Name).Value There is no Value, but in the script it never says TrenchCoat.Value

the script CostumeInator clones the contents and adds them to hats in a folder

You put the copy contents to a parented folder or in the hat?

Can you provide a video of how it’s supposed to work (if possible), and how it currently does it?

Well, it’s supposed to say “$1,000” before you buy it, then once you have it, it should say “Equip” and if its equipped, it says “Equipped.”

Now, the textlabel says “Label”

robloxapp-20230408-1309329.wmv (2.0 MB)

as if the script isnt working at all… no error messages. nothing that says “Infinite Yield possible…”

What about player:WaitForChild("Hat")? Is that supposed to wait for a child of class “Hat”? Because WaitForChild only looks for any Instance named by the given string, or in this case, any object named “Hat”.

Also, using WaitForChild looks to be too abusive of the feature based on your code, mixed with countless CostumeInator scripts looping every tenth of a second.

So there are a missing instance?

If Infinite Yield possible sended in the output because he has don’t founded the targeted instance

um the local script can’t be loaded in a Player Instance?

With the waitforchild("Hat) is not the same as waitforchild(script.parent.parent.parent.Name). waitforchild(script.parent.parent.parent.Name) means “TrenchCoat.” But trenchcoat isnt the only hat. I’m not going to make an individual script for each hat.