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 4 years ago
Edited 4 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:

01GUI:WaitForChild("LevelUp").Event:connect(function(lvl)
02    if allow and Enabled.Value then
03        allow = false
04        Frame.Visible = false
05        Label.Text = "LEVEL UP!"
06        Level.Text = "NEW LEVEL!"
07        local LVL_HUE = math.clamp(tonumber(lvl) or math.random(1, 10) * 100, 1, 1000) / 1000 * 0.8333333333333334
08        local color = Color3.fromHSV(LVL_HUE, 1, 1)
09        for i, v in ipairs(Lines) do
10            v.BackgroundColor3 = color
11            v.BackgroundTransparency = 1
12        end
13        for i, v in ipairs(Lines_LVL) do
14            v.BackgroundColor3 = color
15            v.BackgroundTransparency = 1
View all 23 lines...

THE script where i fire the xp notification:

01function LevelNotify(lvl)
02    Player.PlayerGui.LevelNotify.LevelUp:Fire(lvl)
03end
04function onLevelUp(lvl)
05    Info.XP.Bar.Level.Text = "LEVEL "..lvl
06    setLevel(lvl)
07end
08 
09Database.Notify.OnClientEvent:connect(function(action,...) 
10    local vars = {...}
11    if action == "new tp" then
12        sfx("tick")
13        onPointsAdded(vars[1])
14    elseif action == "new level" then
15        sfx("tick")
View all 26 lines...

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 — 4y
0
Exactly, My mistake. Thanks for correcting me pokemine1o9 44 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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

1local SlowDown = 1
2 
3if SlowDown == 1 then
4    SlowDown = 0
5    -- Event here
6end

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 — 4y
Ad
Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
4 years ago

Try Disabling the script like this

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

Answer this question