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

Why won't the script repeat?

Asked by 6 years ago
Edited 6 years ago

I know I have been asking you a lot, but could you please tell me how I could make this repeat? When I use it, it only works one time. Thank you so much.

01local leaderstats -- We need to get the player before we do anything. Leave blank for now.
02local playersService = game:GetService"Players"
03local debounce = false -- if you don't want it to spam "Raw Robloxs" add this.
04local moneyToGive = 5
05 
06script.Parent.Touched:Connect(function(part)
07    if not debounce and part.Parent.Name == "Pick" then
08        local plr = playersService:GetPlayerFromCharacter(part.Parent.Parent)
09        if plr then -- make sure it's a player
10            debounce = true
11            leaderstats = plr:WaitForChild"leaderstats"
12            leaderstats["Raw Robloxs"].Value = leaderstats["Raw Robloxs"].Value + moneyToGive
13            -- debounce = false -- Debounce reset logic can go here. Reset to false so the code can
14repeat. If you wish for it to not repeat, take this off and it can be a one time touch.
15        moneyToGive = 0 -- set to 0 so it will just give 0 cash.
View all 23 lines...
0
Doesn't it work like this? Repeat wait(1) until Player.Character.Humanoid.Health <= 0 Despayr 505 — 6y
0
Why would I want my health to go down? xD. kittonlover101 201 — 6y
0
So if I understand this correctly, this is to touch a brick and it give you 5 "Raw Robloxs" correct? Azuc 112 — 6y

1 answer

Log in to vote
0
Answered by
Azuc 112
6 years ago
Edited 6 years ago

I'm still figuring things out around here myself but something that caught my eye was this:

On line 04 you define how much to give with the Variable "moneyToGive"

1local moneyToGive = 5

then on line 15 after giving the original 5, you set the "moneyToGive" to 0 so that any consecutive run of the code will reward you with nothing giving the impression it isnt looping.

1moneyToGive = 0
0
Ok. kittonlover101 201 — 6y
Ad

Answer this question