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

Points adding too fast in KotH script - debounce help?

Asked by 5 years ago

Hello,

Working on a King of the Hill-type script. Script works, but the points are adding too fast when the player is touching the part. Any thoughts on how I can adjust the script to where the Points stop being added so fast? Debounce? More Breaks? I've tried putting in a debounce in a couple places, but I appears to be using them incorrectly. I add in waits, but it just delays the mass of points being added at once. I need to make sure points are not being added if the scoreBase is not being touched.

Script:

local function ScorePartTouched(scoreObject)
    local scoreBase = scoreObject.scoreBase
    scoreBase.Touched:connect(function(otherPart)
        local player = Players:GetPlayerFromCharacter(otherPart.Parent)
        wait(1)
        if (player == nil) then return --end 
        elseif (player ~= nil) then
            wait(1)
                PointAdderEvent:Fire(player) --Bindable Event
                return
        end 
    end)
end

The Bindable Event adding the points:

PointAdderEvent.Event:Connect(function(player)
local team1 = game.Teams.Team1
local team2 = game.Teams.Team2
local PlayersT1 = team1:GetPlayers()
local PlayersT2 = team2:GetPlayers()
local replicatedstorage = game:GetService('ReplicatedStorage')
local serversettings = replicatedstorage.ServerSettings
local Team1score = serversettings.Team1Score 
local Team2score = serversettings.Team2Score
        if player.TeamColor == team1.TeamColor then
            Team1score.Value = Team1score.Value + 1
            elseif player.TeamColor == team2.TeamColor then
            Team2score.Value = Team2score.Value + 1
        end
end)

Thank you for taking a look! :)

1
Yes you should use debounce if you want it to trigger with touch, you can also put in a while loop so it keeps adding if they are x studs close to it since standing on a part is not always gonna keep triggering the event. gullet 471 — 5y
0
Thanks for the response! Where you you put the debounces? Never2Humble 90 — 5y
0
Nvm, fixed it! :D Thanks for commenting! Never2Humble 90 — 5y

Answer this question