So I am trying to script this block so that when you touch it it will go transparent over a while then when the transparent and it returns after it is at fully transparent (code not finshed yet). I am unsure what is wrong but I believe it is the transparency if stament.
local part = script.Parent
part.Touched:Connect(function(plr)
local player = plr.Parent:FindFirstChild(“Humanoid”)
if player ~= nil then
print("Human")
while true do
print("Pressed!")
part.Transparency = part.Transparency + 0.1
wait(2)
if part.Transparency == 1 then
part.Transparency = 0
break
end
end
end
What you’re trying to do is inefficient when there’s a better method, like TweenService.
Here’s what a demo of this would look like:
--ts is TweenService
local ti = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local toTransparent = ts:Create(workspace.SomeObject, ti, {Transparency = 1})
toTransparent:Play()
--detect when it finishes the tween:
toTransparent.Completed:Connect(function()
part.SomeObject.Transparency = 0
toTransparent:Play()
end)
I recommend you read further with the link I provided above if you’re still unsure.