So I have a script that displays a popup and it should only display it for about 1 second however the popup stays up for around 10-15 seconds. Here is my code
game.ReplicatedStorage.Remotes.DisplayPopup.OnClientEvent:Connect(function(Gem, amount)
local clone
if Gem then
clone = game.ReplicatedStorage.Gem:Clone()
else
clone = game.ReplicatedStorage.Ruby:Clone()
end
if clone then
local position = UDim2.new('0.'..math.random(100,800),0,'0.'..math.random(100,800),0)
if position.Y.Scale < 0.5 then
clone.Position = UDim2.new(position.X.Scale, 0, -0.25, 0)
else
clone.Position = UDim2.new(position.X.Scale, 0, 1.25, 0)
end
clone.TextLabel.Text = "+ "..amount
clone.Parent = script.Parent
clone:TweenPosition(position, Enum.EasingDirection.Out, Enum.EasingStyle.Elastic, 1, true)
print("Starting Wait")
wait(0.01)
print("Finished Waiting")
clone:Destroy()
end
end)
Here is the output
As you can see there is a 15 second delay. I have tried using wait(1) but that waits for 10 seconds, wait(0.1) waits for about 12 seconds and wait(0.01) waits for about 15 seconds. I also tried wait(5) but that waits for around 15 seconds too. What am I doing wrong? I feel like it’s something to do with the tween but I’m not sure. Any help is hugely appreciated
It might have to do with you tweening the position of the UI element. Try replacing the TweenPosition() with a manual change in the graphic’s position and see if the waiting problem still occurs.
I don’t believe it’s server lag. This is all run on the client and all other scripts seem to be fine. I have a while wait(1) loop in the server to fire the popup and that works perfectly fine and I have other scripts with waits on the client that also work fine. It’s just this one script that waits for so long
And now it waits for the perfect amount of time. It must be something to do with the tweening or position. I also tried setting the position before the parent but that makes it go back to 15 seconds so it must be something to do with the position variable
EDIT: Removing the position variable and putting the UDim in intsead does not fix the issue
You’re firing client from the server 4-5 times, try adding a cooldown to that or provide the server-side code where you use FireClient for DisplayPopup RemoteEvent.
The server code is very simple and it only fires 1 time per second. Here it is
while wait(1) do
if currentPlayerOnHill then
if game.Players:FindFirstChild(currentPlayerOnHill.Name) then
if MarketPlaceService:UserOwnsGamePassAsync(currentPlayerOnHill.UserId, 14726077) then
playerValues[currentPlayerOnHill.UserId][4] += 1
game.ReplicatedStorage.Remotes.DisplayPopup:FireClient(currentPlayerOnHill, false, 2)
else
game.ReplicatedStorage.Remotes.DisplayPopup:FireClient(currentPlayerOnHill, false, 1)
end
playerValues[currentPlayerOnHill.UserId][4] += 1
UpdateLeaderstats(currentPlayerOnHill)
end
end
...
end
RemoteEvents don’t yield. Try using RemoteFunctions instead, it should wait on server until you return a value from client so they shouldn’t stack anymore.
But I do kind of want them to stack and have multiple on screen at a time however this isn’t the problem. The problem is that the wait for some reason doesn’t like the tween or a second position statement and takes 15 seconds instead of 1
Yes this is the whole script. As I said before if I remove the tween completely then it waits for 1 second but when I add the tween or just set the position of it then it waits 15 seconds. I’ve tried creating a tween manually and it still doesn’t work. It tweens in and then waits 15 seconds instead of 1
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.75,Enum.EasingStyle.Elastic,Enum.EasingDirection.Out,0,true,0)
game.ReplicatedStorage.Remotes.DisplayPopup.OnClientEvent:Connect(function(Gem, amount)
print("Running")
local clone
if Gem then
clone = game.ReplicatedStorage.Gem:Clone()
else
clone = game.ReplicatedStorage.Ruby:Clone()
end
if clone then
clone.Parent = script.Parent
local position = UDim2.new('0.'..math.random(100,800),0,'0.'..math.random(100,800),0)
if position.Y.Scale < 0.5 then
clone.Position = UDim2.new(position.X.Scale, 0, -0.25, 0)
else
clone.Position = UDim2.new(position.X.Scale, 0, 1.25, 0)
end
clone.TextLabel.Text = "+ "..amount
--clone:TweenPosition(position, Enum.EasingDirection.Out, Enum.EasingStyle.Elastic, 0.5, true)
local Tween = TweenService:Create(clone,tweenInfo,{Position = position})
Tween:Play()
wait(1)
clone:Destroy()
end
print("Finished")
end)
Right so this has to be a roblox studio issue. I’ve just tested in the real game (which I should’ve done ages ago) and it seems to work perfectly fine in the game. It’s just studio that has this problem. Thanks your help anyways