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)
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.
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