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

Why isn't a point being added to the leader board?

Asked by
Xyternal 247 Moderation Voter
3 years ago

So as i had previously asked, my code won't give me one kill per kill. I get more then one kill. So I added a debouce system. Now, instead of getting any points, i get none. Why does that happen? Here is my script.

ball = script.Parent
damage = 50
local debounce = true
function onTouched(hit)


    local humanoid = hit.Parent:findFirstChild("Humanoid")
    if humanoid~=nil then
        tagHumanoid(humanoid)
        humanoid.Health = humanoid.Health - damage
        if debounce then
            debounce = false
            if humanoid.Health == 0 or humanoid.Health < 0 then
                local z = game.Players:FindFirstChild(game.ReplicatedStorage.asd.Value)
                z.leaderstats.Kills.Value += 1
                wait(2)
                debounce = true
            end
        end

        untagHumanoid(humanoid)

        connection:disconnect()
    else
        damage = damage / 2
        if damage < 2 then
            connection:disconnect()
            ball.Parent = nil

        end
    end

2 answers

Log in to vote
2
Answered by 3 years ago

In this instance do not use connection:Disconnect because it stops the function.

Ad
Log in to vote
1
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago
ball = script.Parent
damage = 50
local debounce = true
function onTouched(hit)


    local humanoid = hit.Parent:findFirstChild("Humanoid")
    if humanoid~=nil then
        tagHumanoid(humanoid)
        humanoid.Health = humanoid.Health - damage
        if debounce then
            debounce = false
            if humanoid.Health == 0 or humanoid.Health < 0 then
                local z = game.Players:FindFirstChild(game.ReplicatedStorage.asd.Value)
                z.leaderstats.Kills.Value += 1
                wait(2)
                debounce = true
            end
        end

        untagHumanoid(humanoid)
    else
        damage = damage / 2
        if damage < 2 then
            ball.Parent = nil
        end
    end

don't use connection:Disconnect() on this situation, if it dont have lines it doesnt run anything, connection:Disconnect() only stops the function and it's unable to get listened, basically disable the function

Heres a very cool explanation by roblox:

Always call Disconnect() when a connection is no longer needed. Forgetting to do so can cause your game to use more resources than necessary. Note, however, that this may not always be necessary; when an object is destroyed, all connections to that object’s events are disconnected automatically.

0
So in other words, this kinda feels like the disconnect isn't whats wrong, the way roblox explained it. Remember, im not getting any points even if i died 500 times Xyternal 247 — 3y
0
your answer doesn't work. Please check again Xyternal 247 — 3y
0
Wat Xapelize 2658 — 3y
0
it doesnt work Xyternal 247 — 3y
View all comments (32 more)
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
it doesnt work lol Xyternal 247 — 3y
0
WHAT THE HELL 31 NOTIFCATIONS I GONNA DIN YOU Xapelize 2658 — 3y

Answer this question