This script sometimes gives up to 50 player points per touch but its only set to give 10. I know why but I dont know how to fix it. Here is the code.
01 | local Part = script.Parent |
02 |
03 | Part.Touched:connect( function (part) |
04 | local player = game.Players:GetPlayerFromCharacter(part.Parent) |
05 |
06 | if part:IsA( "Part" ) and (player) then |
07 | local points = game:GetService( "PointsService" ) |
08 |
09 | if points:GetAwardablePoints() > = 0 then |
10 | points:AwardPoints(player.userId, 10 ) |
11 | wait() |
12 | script:remove() |
13 | wait( 5 ) |
14 |
15 | end |
16 | end |
17 | end ) |
I'm assuming your problem is that both legs are touching the part at the same time, and possibly walking on and off the part. Add some sort of debounce into your code like so:
01 | local Part = script.Parent |
02 | local deb = false --set the variable |
03 |
04 | Part.Touched:connect( function (part) |
05 | if deb = = false then --make sure it's false, so you don't spam the button |
06 | deb = true --set it to true so it won't run the code again until it's false |
07 | local player = game.Players:GetPlayerFromCharacter(part.Parent) |
08 |
09 | if part:IsA( "Part" ) and (player) then |
10 | local points = game:GetService( "PointsService" ) |
11 |
12 | if points:GetAwardablePoints() > = 0 then |
13 | points:AwardPoints(player.userId, 10 ) |
14 | wait() |
15 | script:remove() |
Hope I helped!