Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Second tween won't play?

Asked by 5 years ago
Edited 5 years ago

What is the problem with the second tween? the first tween worked, but the second one just won't work. Even if I remove the first tween, it still won't work. Is there something wrong?

It's basically a health detector, so if a player lose some, the gui color changes, but I want the color change to be smooth. So I used tween, the first tween worked, but the second one didn't, I don't know why

player = game.Players.LocalPlayer
healthcolor = script.Parent.Frame.ImageLabel
textbox = script.Parent.Frame.ImageLabel.TextBox
local TweenService = game:GetService('TweenService')
local tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear)

player.CharacterAdded:connect(function(character)
    local humanoid = character:WaitForChild("Humanoid")
    humanoid.HealthChanged:connect(function(health)

if health >= 81 and health <=100 then
    healthcolor.ImageColor3 = Color3.new(0,255,0)
    textbox.Text = 5
end
if health >= 61 and health <=80 then
    healthcolor.ImageColor3 = Color3.new(0,255,0)
    textbox.Text = 4
end
if health >= 41 and health <=60 then
    healthcolor.ImageColor3 = Color3.new(0,255,0)
    local tween = TweenService:Create(healthcolor, tweeninfo, 
    {ImageColor3 = Color3.fromRGB(255,255, 0)})
    tween:Play()
    wait(0.5)
    healthcolor.ImageColor3 = Color3.new(255,255,0)
    textbox.Text = 3
end
if health >= 21 and health <=40 then
    healthcolor.ImageColor3 = Color3.new(255,255,0)
    textbox.Text = 2
end
if health >= 1 and health <=20 then
    healthcolor.ImageColor3 = Color3.new(255,255,0)
    local tween = TweenService:Create(healthcolor, tweeninfo, 
    {ImageColor3 = Color3.fromRGB(255,0, 0)})
    tween:Play()
    wait(0.5)
    healthcolor.ImageColor3 = Color3.new(255,0,0)
    textbox.Text = 1
    while true do
    textbox.TextColor3 = Color3.new(255,0,0)
    wait(0.5)
    textbox.TextColor3 = Color3.new(0,0,0)
    wait(0.5)
end
end
if health == 0 then
    healthcolor.ImageColor3 = Color3.new(255,0,0)
    textbox.Text = 0    
    textbox.TextColor3 = Color3.new(255,0,0)
end
end)
end)

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
0
can you show the whole thing? when does the code run? GoldAngelInDisguise 297 — 5y
0
done! MArzalAlBuchariZ 33 — 5y
0
You might be advised to use elseif. User#25115 0 — 5y
0
I don't know if elseif will have the same effect tho, let's just not focus on that. MArzalAlBuchariZ 33 — 5y
0
Anyways, I'm going to sleep. If someone answered my question while I was asleep. thanks a lot! MArzalAlBuchariZ 33 — 5y

Answer this question