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

Help with making it give only 10 per touch?

Asked by 9 years ago

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.

01local Part = script.Parent
02 
03Part.Touched:connect(function(part)
04local player = game.Players:GetPlayerFromCharacter(part.Parent)
05 
06if part:IsA("Part") and (player) then
07local points = game:GetService("PointsService")
08 
09if points:GetAwardablePoints() >= 0 then
10points:AwardPoints(player.userId, 10)
11wait()
12script:remove()
13wait(5)
14 
15end
16end
17end)

1 answer

Log in to vote
0
Answered by
KLGA 0
9 years ago

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:

01local Part = script.Parent
02local deb = false --set the variable
03 
04Part.Touched:connect(function(part)
05if deb == false then --make sure it's false, so you don't spam the button
06deb = true --set it to true so it won't run the code again until it's false
07local player = game.Players:GetPlayerFromCharacter(part.Parent)
08 
09if part:IsA("Part") and (player) then
10local points = game:GetService("PointsService")
11 
12if points:GetAwardablePoints() >= 0 then
13points:AwardPoints(player.userId, 10)
14wait()
15script:remove()
View all 23 lines...

Hope I helped!

Ad

Answer this question