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

GUI Tween on EXP gain?

Asked by
Zyleak 70
8 years ago

Basically, I want the GUI to open when the player gains EXP. So far it opens fine but wont close. I have a time set which it is open for before closing. The time seems to go down by 5 instead of going to 5 and taking away 1 each second.

local Player = game.Players.LocalPlayer
local Data = Player:WaitForChild("Data")
local Time = script.Parent:WaitForChild("Time")
local Frame = script.Parent
Data.Exp.Changed:connect(function(property)
Time.Value = 5
Frame:TweenPosition(UDim2.new(0.3, 0,0, 60), "Out", "Quad", 0.5, true)
end)
Time.Changed:connect(function(property)
    if Time.Value > 0 then
    repeat
    Time.Value = Time.Value -1
    wait(1)
    until Time == 0 
    elseif Time.Value == 0 then
    Frame:TweenPosition(UDim2.new(0.3, 0,0, -100), "Out", "Quad", 0.5, true)
    wait(1)
end
end)

1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
8 years ago

Yo Prob

Your problem is the Time.Changed function in your script. When it fires, you're changing the Time's value, so that it fires again, and changes the value again, without waiting.


Whoo, TIME To Fix It

Ok, so to fix this, well simply remove the function, and the script should pretty much work fine after that:

local Player = game.Players.LocalPlayer
local Data = Player:WaitForChild("Data")
local Time = script.Parent:WaitForChild("Time")
local Frame = script.Parent
Data.Exp.Changed:connect(function(property)
    Time.Value = 5
    Frame:TweenPosition(UDim2.new(0.3, 0,0, 60), "Out", "Quad", 0.5, true)
    if Time.Value > 0 then
        repeat
            Time.Value = Time.Value -1
            wait(1)
        until Time == 0 
    elseif Time.Value == 0 then
        Frame:TweenPosition(UDim2.new(0.3, 0,0, -100), "Out", "Quad", 0.5, true)
        wait(1)
    end
end)

Yea, so now it should pretty much work how you wanted it to.


Anyways, if you have any further problems/questions, hit me up in the comments, and i'll see what I can do. Hope I helped :P

-Dyler3

Ad

Answer this question