Part turning neon when player can afford the button

Hello forummers, Ive been making a button simulator and i was wondering how i could be able to make the part of the buttons turn neon in material when the players can afford to buy the buttons. Ive tried alot of things yet none of them worked.

this is my script (theres more in it):

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Modules = ReplicatedStorage:WaitForChild("Modules")

local EternityNum = require(Modules.EternityNum)
local StatModule = require(Modules.StatModule)
local Relics = require(Modules.Relics)

local ButtonFunctions = {}

function ButtonFunctions.GetStatFromName(Stat) -- finds statnumber from stat name	
	for i,v in StatModule do
		if v.StatName == Stat then
			return i
		end
	end 
	return nil
end

function ButtonFunctions.BuyButton(Player, Button, Stat)
	local StatNumber = ButtonFunctions.GetStatFromName(Stat)
	if StatNumber then
		Button = tonumber(Button.Name)

		local StatInfo = StatModule[StatNumber]

		local BuyStat = StatModule[StatInfo.BuyStat]
		local Bought = false

		--// Can you afford the stat?
		if BuyStat then -- one buy stat
			local ConvertedStat,ConvertedCost = EternityNum.convert(Player.Data.Stats[BuyStat.StatName].Value), EternityNum.convert(StatInfo.Buttons[Button].Cost)
			if EternityNum.meeq(ConvertedStat,ConvertedCost) then
				Bought = true
			end
		end

		if not Bought then return end

		-- Resets
		local StatsToReset = StatInfo.BuyStat
		if not StatModule[StatInfo.BuyStat] then StatsToReset = StatsToReset[2] end -- buystat or 2nd buystat

		for i = StatsToReset, 1, -1 do
			Player.Data.Stats[StatModule[i].StatName].Value = StatModule[i].StartingValue
		end

		--// Find Stat Above
		local StatAbove = {1,0,1}

		if not StatInfo.MultiplyingStat then -- if MultiplyingStat is not Setup then the multiplier is the stat above
			local StatInfoAbove = StatModule[StatNumber+1]

			if StatInfoAbove then
				StatAbove = EternityNum.add(StatAbove, EternityNum.convert(Player.Data.Stats[StatInfoAbove.StatName].Value)) -- StatAbove = 1 + howmuch u got
			end
		else
			local MStat = StatInfo.MultiplyingStat
			if StatModule[MStat] then -- normal
				StatAbove = EternityNum.add(StatAbove, EternityNum.convert(Player.Data.Stats[StatModule[MStat].StatName].Value)) -- Multiplying = 1 + howmuch u got
			end
		end

		--// Calculate the multipliers
		local Gain = EternityNum.convert(StatInfo.Buttons[Button].Gain)
		local Multiplier = EternityNum.mul(Gain, StatAbove)
		local StatMultiplier = StatInfo.StatMultiplier(Player.Data)

		if StatMultiplier ~= 1 then
			Multiplier = EternityNum.mul(Multiplier, EternityNum.convert(StatMultiplier))
		end

		--// Add to values
		local Addition = EternityNum.add(Multiplier, EternityNum.convert(Player.Data.Stats[Stat].Value)) -- Multiplier + CurrentStatValue
		Player.Data.Stats[Stat].Value = EternityNum.toString(Addition)		
		Player.Data.PlayerData["Buttons Pressed"].Value += 1
		--Player.Data.Stats.Tokens.Value += math.random(0.001,0.05) * (Player.Data.Upgrades.Tokens.Value * 1.25)
		end
	end

this is my buttons hirearchy:
image
keep in mind, i want the Forcefield object to be the one to turn neon

image

You can put a LocalScript inside of StarterPlayerScripts to do this, I provided an example and video below on how it works. :smiley:

Create a LocalScript inside of StarterPlayerScripts and name it “ButtonManager” (or whatever you want)

An example of the code you would use within this script is:

local player = game:GetService("Players").LocalPlayer
local button = game.Workspace.Button -- Change to your buttons location

local function changeButton()
	if player:WaitForChild("leaderstats").Cash.Value >= 1000 then -- Enter the cost here then
		button.Material = Enum.Material.Neon
	end
end

player:WaitForChild("leaderstats").Cash.Changed:Connect(function()
	changeButton()
end)

Let me know if this works for you

thats one problem, basically i have multiple buttons who each have different prices that are defined in a module script here:

In here is the Functions module script which i sent earlier is:
image

and in the ButtonHandler is this:

--// Variables

local ButtonFunctions = require(script.Functions)

local HumanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart")

local Player = game.Players:GetPlayerFromCharacter(script.Parent)
local CharSize = Vector3.new(0.5,script.Parent:GetExtentsSize().Y + 1,0.5) -- char

repeat task.wait() until Player:FindFirstChild("Loaded") and Player.Loaded.Value or Player.Parent == nil

if Player.Parent == nil then return end

--// Main Script

local DB = false

while task.wait(0.03) do 
	local PartsInRegion = workspace:GetPartBoundsInBox(HumanoidRootPart.CFrame - Vector3.new(0, 1, 0), CharSize)
	local WaitTime = 0.03
	
	local FoundOre = false
	
	for _, Part in PartsInRegion do
		if Part.Name ~= "Touch" then continue end
		
		--// Relic
		if Part:IsDescendantOf(workspace.Main.Relics) then
			local Relics = Part.Parent.Name

			local suc,er = pcall(function()
				ButtonFunctions.BuyRelic(Player, Relics)
				WaitTime = 0.2 -- relic wait time
				DB = true
			end)
			if er then warn("Error while pressing relic: "..er) end
			break
			
		--// Button
		elseif Part:IsDescendantOf(workspace.Main.Buttons) then
			local Stat = Part.Parent.Parent.Name

			local suc,er = pcall(function()
				ButtonFunctions.BuyButton(Player, Part.Parent, Stat)
				WaitTime = 0.1 -- button wait time
				DB = true
			end)

			if er then warn("Error while pressing button: "..er) end
			break -- break the loop when the button part has been found
		end
	end
	
	if DB then task.wait(WaitTime-0.03) end -- loop every 0.05 seconds but wait longer when touched a button to create the real cooldown
end

any other solution to this then defining it in a local script like you suggested?

still available if someone is down to help :+1: