Im trying to make a loop play and continue the function, but I do not know how to do this.
db = true
script.Parent.MouseButton1Click:Connect(function()
if db == false then return end
db = true
local value = 0
while true do --loop starts here
wait(0.1)
script.Parent.CanvasGroup.Frame.Visible = true
value += 0.1
script.Parent.CanvasGroup.Frame.Position += UDim2.new(0,0,0.01,0)
script.Parent.CanvasGroup.TextLabel.Visible = true
local newvalue = math.round(value / 100) * 100
script.Parent.CanvasGroup.TextLabel.Text = string.format("%0.1f", 10 - value)
if script.Parent.CanvasGroup.Frame.Position.Y.Scale >= 1 then
script.Parent.CanvasGroup.Frame.Visible = false
script.Parent.CanvasGroup.Frame.Position = UDim2.new(0,0,0,0)
script.Parent.CanvasGroup.TextLabel.Visible = false
db = true
return
end
end
local character = game.Players.LocalPlayer.Character
for i,v in pairs(character:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("Decal") then -- if it is a part
v.LocalTransparencyModifier = 0.5
v.Transparency = 0.5
table.insert(characterTransparencyConnections, v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
v.LocalTransparencyModifier = 0.5
end))
table.insert(characterTransparencyConnections, v:GetPropertyChangedSignal("Transparency"):Connect(function()
v.Transparency = 0.5
end))
end
end
game.ReplicatedStorage.Abilites.Invis:FireServer()
task.wait(3)
stopTransparencyConnection()
for i,v in pairs(character:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("Decal") then -- if it is a part
v.LocalTransparencyModifier = 0
v.Transparency = 0
table.insert(characterTransparencyConnections, v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
v.LocalTransparencyModifier = 0
end))
table.insert(characterTransparencyConnections, v:GetPropertyChangedSignal("Transparency"):Connect(function()
v.Transparency = 0
end))
end
end
stopTransparencyConnection()
game.Players.LocalPlayer.Character.HumanoidRootPart.Transparency = 1
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Edit: Just realized something. I think I misunderstood your question.
The reason the code underneath the loop wont execute is because you are using “return” to exit the loop. Use break instead. Then after the loop is done the code underneath it will execute.
If you want to have the code below it executed before the loop since the loop will cause a delay:
As the reply above says I would also just recommend to move the code underneath the while loop to above it and that should fix it for you.
But for future reference if you run into a problem where you can’t move the code you can look up coroutines.
you can use task.spawn() to make it run without blocking the rest of the code
db = true
script.Parent.MouseButton1Click:Connect(function()
if db == false then return end
db = true
local value = 0
task.spawn(function()
while true do --loop starts here
wait(0.1)
script.Parent.CanvasGroup.Frame.Visible = true
value += 0.1
script.Parent.CanvasGroup.Frame.Position += UDim2.new(0,0,0.01,0)
script.Parent.CanvasGroup.TextLabel.Visible = true
local newvalue = math.round(value / 100) * 100
script.Parent.CanvasGroup.TextLabel.Text = string.format("%0.1f", 10 - value)
if script.Parent.CanvasGroup.Frame.Position.Y.Scale >= 1 then
script.Parent.CanvasGroup.Frame.Visible = false
script.Parent.CanvasGroup.Frame.Position = UDim2.new(0,0,0,0)
script.Parent.CanvasGroup.TextLabel.Visible = false
db = true
return
end
end
end)
local character = game.Players.LocalPlayer.Character
for i,v in pairs(character:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("Decal") then -- if it is a part
v.LocalTransparencyModifier = 0.5
v.Transparency = 0.5
table.insert(characterTransparencyConnections, v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
v.LocalTransparencyModifier = 0.5
end))
table.insert(characterTransparencyConnections, v:GetPropertyChangedSignal("Transparency"):Connect(function()
v.Transparency = 0.5
end))
end
end
game.ReplicatedStorage.Abilites.Invis:FireServer()
task.wait(3)
stopTransparencyConnection()
for i,v in pairs(character:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("Decal") then -- if it is a part
v.LocalTransparencyModifier = 0
v.Transparency = 0
table.insert(characterTransparencyConnections, v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
v.LocalTransparencyModifier = 0
end))
table.insert(characterTransparencyConnections, v:GetPropertyChangedSignal("Transparency"):Connect(function()
v.Transparency = 0
end))
end
end
stopTransparencyConnection()
game.Players.LocalPlayer.Character.HumanoidRootPart.Transparency = 1
end)