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

GIVE JUST ONE POINTS (OnTouched) - Part ?

Asked by 7 years ago
Edited 7 years ago

i need help for something. it my script (i want Exemple if someone touch the part that give one points only) INFO : WHEN I TOUCH IT, IT GIVE 160 POINTS AND I JUST ONE ONLY 1 POINT

1WinPlace1 = script.Parent
2WinPlace1.Touched:connect(function()
3    print(game.Players.LocalPlayer)
4    wait(3)
5    game.Players.LocalPlayer.leaderstats.point.Value= game.Players.LocalPlayer.leaderstats.point.Value +1
6end)
0
That's because you're touching the brick infinite times for second. To fix that add like a Cooldown, a debounce. Kiriyato 15 — 7y

2 answers

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

You'll want to add a debounce, here's the new code.

01WinPlace1 = script.Parent
02Debounce = false
03 
04WinPlace1.Touched:connect(function()
05    print(game.Players.LocalPlayer)
06 
07if Debounce == false then
08Debounce = true
09 
10    game.Players.LocalPlayer.leaderstats.point.Value= game.Players.LocalPlayer.leaderstats.point.Value +1
11 
12Debounce = false
13end
14end)
Ad
Log in to vote
0
Answered by 7 years ago

@helperobc That's a good way to do it too

Here's another way (Add a delay):

1WinPlace1 = script.Parent
2WinPlace1.Touched:connect(function()
3script.Disabled = true
4    print(game.Players.LocalPlayer)
5    wait(3)
6    game.Players.LocalPlayer.leaderstats.point.Value= game.Players.LocalPlayer.leaderstats.point.Value +1
7wait(5)
8script.Disabled = false
9end)
0
that also works, I guess it really depends on how the developer wants to do it. helperobc 52 — 7y

Answer this question