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

Why does this give out 7 points?!?!

Asked by 10 years ago

I have a Motorcross game (Fairly popular) and every time someone crosses the finish, it awards 7 points! Not 1! At the rate it's going, it'll run out in 40 races!

local part = script.Parent

debounce = false
part.Touched:connect(function(part)
    if debounce == false then
        debounce = true

        local g = game.Players:GetPlayerFromCharacter(part.Parent)
        if part:IsA("Part") and (g) then
        pps = game:GetService("PointsService")
        if pps:GetAwardablePoints() >= 1 then
            wait(3)
         pps:AwardPoints(g.userId, 1)
        end

        wait(.2)
        debounce = false
end) -- Got the red squiggly line thing!


3 answers

Log in to vote
0
Answered by 10 years ago

My best guess is that you need to add debounce.

debounce = false
part.Touched:connect(function(part)
    if debounce == false then
        debounce = true

        --your code

        wait(.2)
        debounce = false
end)

You can read about debounce here.

0
Thats what I told him yesterday.. Tempestatem 884 — 10y
0
Great minds think alike :) LightArceus 110 — 10y
0
Yeah, but both your's didn't work. Tempestem had a red quiggly line thing (No idea what their called...) on 'end)' and adding a third end broke the script whilst adding yours, had the red line under ' if debounce = false then' and addming my code didn't work. Both "great" minds didn't exactly work... Michael007800 144 — 10y
0
It should be if debounce == false, my bad. LightArceus 110 — 10y
View all comments (2 more)
0
Check the code now. I updated teh question. Also, the end) has the error squaiggly line! Michael007800 144 — 10y
0
If you hover your mouse over the red line, it should tell you in the bottom left corner of Studio what the error is. In this case it is that you need one more end. It should go right after debounce = false. LightArceus 110 — 10y
Ad
Log in to vote
0
Answered by
KAAK82 16
10 years ago

Add a Debounce, and Add some wait()'s so that it would wait a little before giving the Player their Points, cos if u don't add a wait() then sometimes things do stuff as if they were called multiple times... I've Experienced that a ton of times...

Edit:

local part = script.Parent
local Touching = false

part.Touched:connect(function(part)
if not Touching then
Touching = true
local g = game.Players:GetPlayerFromCharacter(part.Parent)
if part:IsA("Part") and (g) then
pps = game:GetService("PointsService")
if pps:GetAwardablePoints() >= 1 then
    pps:AwardPoints(g.userId, 1)
    wait(1) --This wait() will make everything Stop for 1 Second after the Player Point is Awarded, so that if your still Touching the Part it'll wait 1 Second so as not to keep giving u Points, it's basically like FireRate in a Gun but except there's only 1 Bullet... (And wen I said everything, I meant the Point Awarding)
Touching = false
end
script.Parent:destroy()
end
end)
0
Once again, trying Debounce broke the script. Unless someone can help me by giving me an example the script, sorry but there is no help... (Or atleast where to put the debounces...) Michael007800 144 — 10y
Log in to vote
0
Answered by 10 years ago

I'm pretty sure the problem with the current script is that it needs more ends.

part.Touched:connect(function(part)

This one needs an end).

if debounce == false then
if part:IsA("Part") and (g) then
 if pps:GetAwardablePoints() >= 1 then

All 3 of these need ends. Looking at your script, it only has two ends when it needs four. I hope this helps.

Answer this question