Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't the script repeat?

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.

local leaderstats -- We need to get the player before we do anything. Leave blank for now.
local playersService = game:GetService"Players"
local debounce = false -- if you don't want it to spam "Raw Robloxs" add this.
local moneyToGive = 5

script.Parent.Touched:Connect(function(part)
    if not debounce and part.Parent.Name == "Pick" then
        local plr = playersService:GetPlayerFromCharacter(part.Parent.Parent)
        if plr then -- make sure it's a player
            debounce = true
            leaderstats = plr:WaitForChild"leaderstats"
            leaderstats["Raw Robloxs"].Value = leaderstats["Raw Robloxs"].Value + moneyToGive
            -- debounce = false -- Debounce reset logic can go here. Reset to false so the code can 
repeat. If you wish for it to not repeat, take this off and it can be a one time touch.
        moneyToGive = 0 -- set to 0 so it will just give 0 cash. 
            wait(1)
       end
    end
end)

script.Parent.TouchEnded:Connect(function(part)
    debounce = false -- Debounce logic can go here if you want it to reset after it stops touching.
end)


3 comments

0

Doesn't it work like this? Repeat wait(1) until Player.Character.Humanoid.Health <= 0

0

Why would I want my health to go down? xD.

0

So if I understand this correctly, this is to touch a brick and it give you 5 "Raw Robloxs" correct?

1 answer

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"

local 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.

moneyToGive = 0

1 comment

0

Ok.

This discussion is preserved as it was. New answers, comments, and votes are closed.