Hello, I’m new to scripting and trying to understand things I don’t fully understand in Lua.
I’m currently stuck, as I have made two separate bricks. One has the transparency stored in the variable, while the second one doesn’t. Why is this happening?
v First Example v - This one half-works, where it only shows the “brickTransparency” going up, but that’s it. The visibility of the brick will remain the same.
local Brick = script.Parent
local brickTransparency = Brick.Transparency
local looping = true
local function IWasTouched(Part)
local partParent = Part.Parent
local Robloxian = Part.Parent:FindFirstChild("Humanoid")
if Robloxian and brickTransparency < 1 then
print("WE'RE AT THE START")
while looping and brickTransparency < 1 do
looping = false
print("Looping")
brickTransparency = brickTransparency + 0.1
print(brickTransparency)
wait(0.5)
looping = true
end
end
end
Brick.Touched:Connect(IWasTouched)
v Second Example v - This one works perfectly fine. Upon being touched it will show the transparency of the block while gradually disappearing
local Brick = script.Parent
local brickTransparency = Brick.Transparency
local looping = true
local function IWasTouched(Part)
local partParent = Part.Parent
local Robloxian = Part.Parent:FindFirstChild("Humanoid")
if Robloxian and Brick.Transparency < 1 then
print("WE'RE AT THE START")
while looping and Brick.Transparency < 1 do
looping = false
print("Looping")
Brick.Transparency = Brick.Transparency + 0.1
print(Brick.Transparency)
wait(0.5)
looping = true
end
end
end
Brick.Touched:Connect(IWasTouched)