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

Event Firing Again and again after fired once??? XP Notification

Asked by 3 years ago
Edited 3 years ago

Im having this issue: My notify script where its meant to pop up with this specific level up message which it does but once it does it just loops and loops . Its meant to fire each time a new level. help!

LevelNotify Script:

GUI:WaitForChild("LevelUp").Event:connect(function(lvl)
    if allow and Enabled.Value then
        allow = false
        Frame.Visible = false
        Label.Text = "LEVEL UP!"
        Level.Text = "NEW LEVEL!"
        local LVL_HUE = math.clamp(tonumber(lvl) or math.random(1, 10) * 100, 1, 1000) / 1000 * 0.8333333333333334
        local color = Color3.fromHSV(LVL_HUE, 1, 1)
        for i, v in ipairs(Lines) do
            v.BackgroundColor3 = color
            v.BackgroundTransparency = 1
        end
        for i, v in ipairs(Lines_LVL) do
            v.BackgroundColor3 = color
            v.BackgroundTransparency = 1
        end
        Frame.Position = UDim2.new(0.5, 0, 0.45, 0)
        Label.TextTransparency, Level.TextTransparency = 1, 1
        Label.TextColor3, Level.TextColor3 = color, color
        animateGUI()
        allow = true
    end
end)

THE script where i fire the xp notification:



function LevelNotify(lvl) Player.PlayerGui.LevelNotify.LevelUp:Fire(lvl) end function onLevelUp(lvl) Info.XP.Bar.Level.Text = "LEVEL "..lvl setLevel(lvl) end Database.Notify.OnClientEvent:connect(function(action,...) local vars = {...} if action == "new tp" then sfx("tick") onPointsAdded(vars[1]) elseif action == "new level" then sfx("tick") onLevelUp(vars[1]) LevelNotify(vars[1]) elseif action == "new xp" then sfx("tick") onXPChange(vars[1]) end end) onLevelUp(sendControl("get level")) onPointsAdded(sendControl("get tp")) onXPChange(sendControl("get xp"))

All i need is for it to stop looping and only fire when u hit "new level".

0
Set a variable or something that is set false, then set it true whenever it fires the remote. make it so if its true it cant call again TheBeastMare 3 — 3y
0
Exactly, My mistake. Thanks for correcting me pokemine1o9 44 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Maybe try adding some kind of system, something like this:


local SlowDown = 1 if SlowDown == 1 then SlowDown = 0 -- Event here end

I'm not sure but this may help to not trigger it twice, and if you're going to have it fire more than once you're going to have to reset SlowDown to 1after the event is fired. It's my best guess as to what is happening.

0
debounce is what you're trying to say. It's the same concept, but it uses booleans instead of integers. Dovydas1118 1495 — 3y
Ad
Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

Try Disabling the script like this

game.Workspace.YOUR PART LOCATION.YOUR PART.Touched:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        game.ReplicatedStorage.YOUR EVENT HERE:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
        script.Parent.Disabled = true
        wait(5)
        script.Parent.Disabled = false
    end
end)

Answer this question