Help With Goal System

I am making a goal system. I got it down to the script below. The problem is that the UI stays up for a very long time and then goes a way. I want it to only wait 3 seconds and the disappear. How do I fix this

local part= script.Parent

local function showUI(frame)
    for _, Player in pairs(game.Players:GetChildren()) do
        Player.PlayerGui.GoalAlert.MainFrame.Visible = true
        Player.PlayerGui.GoalAlert.MainFrame[frame].Visible = true
        wait(3) 
        Player.PlayerGui.GoalAlert.MainFrame.Visible = false
        Player.PlayerGui.GoalAlert.MainFrame[frame].Visible = false
    end
end

local function oHitBox()
    showUI("Blue")
end

local function bHitBox()
    showUI("Red")
end

part.Touched:Connect(function(hit)
    if hit.Name == "OHitBox" then
        oHitBox()
    elseif hit.Name == "BHitBox" then
        bHitBox()
    end
end)

Okay so from reading the code I assume your running this code on the server side of the experience but when changing UI it should be done locally instead. Rather then running this code on the server you should fire a remote event and then change the UI on the local side. This possibly could be causing the issue because there will be a delay due to it being run on the server.

Also I don’t really see the point of the “oHitBox” function because you might as well just run the “showUI” function directly just adding the colour in there. Although this should not slow it down by much by theory this could slow it down a tiny bit as it has to go through two functions.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.