This is unrelated to your problem, but I’m quite sure that “hi3” won’t be printed since it’s blocked by the while loop that’s right above it due to the fact that the loop isn’t running in a separate thread
@rusted010101 This is admittedly a quick fix so it might not work, but you’ll need to do something like this to wait for the Tweens to finish playing before the loops continue:
local tS = game:GetService("TweenService")
local tI = TweenInfo.new(0.5, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0)
local GoalsTransparency0 = {
Transparency = 0
}
local GoalsTransparency1 = {
Transparency = 1
}
local BoolVal = script.Parent.Buyable
script.Parent.Head.Touched:Connect(function(hit)
if script.Parent.Buyable.Value == true then
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent:FindFirstChild("Owns") then
if hit.Parent.Owns.Value == script.Parent.Parent.Parent.Name then
BoolVal.Value = false
end
end
end
end
end)
print("hi")
function Check()
if BoolVal.Value == true then
for _, v in pairs(script.Parent.Head:GetChildren()) do
if v then
local Tween1 = tS:Create(script.Parent.Head.BillboardGui2.Text, tI, {TextTransparency = 0})
Tween1:Play()
local Tween2 = tS:Create(script.Parent.Head.BillboardGui1.Frame, tI, {ImageTransparency = 0})
Tween2:Play()
local Tween3 = tS:Create(script.Parent.Head.BillboardGui1.Frame.Frame, tI, {ImageTransparency = 0})
Tween3:Play()
local Tween4 = tS:Create(script.Parent.Head.BillboardGui1.Frame.Frame.Text, tI, {TextTransparency = 0})
Tween4:Play()
Tween4.Completed:Wait()
if v:IsA("UnionOperation") or v:IsA("MeshPart") then
local TweenTransparency0 = tS:Create(v, tI, GoalsTransparency0)
TweenTransparency0:Play()
TweenTransparency0.Completed:Wait()
end
for _, i in pairs(script.Parent.Head.Glow:GetChildren()) do
if i:IsA("Decal") then
local TweenTransparency0 = tS:Create(i, tI, GoalsTransparency0)
TweenTransparency0:Play()
TweenTransparency0.Completed:Wait()
end
end
if script.Parent:FindFirstChild("Head") then
local TweenTransparency0 = tS:Create(script.Parent.Head, tI, GoalsTransparency0)
TweenTransparency0:Play()
TweenTransparency0.Completed:Wait()
end
end
end
else
for _, v in pairs(script.Parent.Head:GetChildren()) do
if v then
if v:IsA("UnionOperation") or v:IsA("MeshPart") then
local TweenTransparency1 = tS:Create(v, tI, GoalsTransparency1)
TweenTransparency1:Play()
TweenTransparency1.Completed:Wait()
end
if v:FindFirstChildWhichIsA("Decal") or v:FindFirstChildWhichIsA("Texture") then
local TweenTransparency1 = tS:Create(v:FindFirstChildWhichIsA("Decal") or v:FindFirstChildWhichIsA("Texture"), tI, GoalsTransparency1)
TweenTransparency1:Play()
TweenTransparency1.Completed:Wait()
end
local Tween1 = tS:Create(script.Parent.Head.BillboardGui2.Text, tI, {TextTransparency = 1})
Tween1:Play()
local Tween2 = tS:Create(script.Parent.Head.BillboardGui1.Frame, tI, {ImageTransparency = 1})
Tween2:Play()
local Tween3 = tS:Create(script.Parent.Head.BillboardGui1.Frame.Frame, tI, {ImageTransparency = 1})
Tween3:Play()
local Tween4 = tS:Create(script.Parent.Head.BillboardGui1.Frame.Frame.Text, tI, {TextTransparency = 1})
Tween4:Play()
Tween4.Completed:Wait()
end
end
end
end
print("hi2")
task.spawn(function()
while true do
Check()
task.wait()
end
end)
print("hi3")
Essentially I added .Completed:Wait()
like @x6nnx suggested. Using :Wait
instead of :Connect
allows you to wait for an event to fire without having to worry about memory leaks due to connections