Appearing pillars not working

I’m not sure why this isn’t working, I am not the best at scripting and would appreciate some help.
The pillars are meant to appear and change material once the player can step on it.

local Brick = script.Parent
local Pillar = workspace.Pillar1

local function PlayerTouched(Part)
	Pillar.BrickColor = BrickColor.new("Red flip/flop")
	Pillar.Material = Enum.Material.ForceField
	while true do
		wait(0.01)
		Pillar.Transparency -= 0.01
		if Pillar.Transparency == 0 then
			Pillar.CanCollide= true
			Pillar.BrickColor = BrickColor.new(165, 129, 86)
			Pillar.Material = Enum.Material.Slate
			script.Disabled = true
		end
	end
end


Brick.Touched:connect(PlayerTouched)

local Brick = script.Parent
local Pillar = workspace.Pillar1

local debounce = false -- to prevent the function run multiple time when touched
local function PlayerTouched(Part)
	if debounce then return end
	debounce = true
	Pillar.BrickColor = BrickColor.new("Red flip/flop")
	Pillar.Material = Enum.Material.ForceField
	while true do 
		wait(0.01)
		Pillar.Transparency -= 0.01
		if Pillar.Transparency <= 0 then --must put <= 0 if not it won't work
			Pillar.CanCollide= true
			Pillar.BrickColor = BrickColor.new(165, 129, 86)
			Pillar.Material = Enum.Material.Slate
			--script.Disabled = true --Can only stop the script through other script, the script disabled but the while loop still running
			break --exit loop
		end
	end
	wait(.3)
	debounce = false
end

Brick.Touched:connect(PlayerTouched)

Thanks a lot for helping me, I hope you have a great day.

1 Like