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

Making a custom sonic ring counter, how to add up by tens?

Asked by 7 years ago
Edited 7 years ago

So throw this script in a ring or block or something in workspace,

**There are three inValues for the rings in StarterGui, a Ones place intvalue, tens intvalue and Hundreds place Intvalue. ** So if I touch a 10 ring, and if I already touch 1 ring I want the value to go up by 9 and then 0.0001 seconds later automatically add by 1.

I'm doing this because if the Value of an IntValue is 10 then the IntValue is supposed reset to 0 instantly.

function Touch(Item)
    if Item.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(Item.Parent)  then
        local PlayerGui = game.Players:GetPlayerFromCharacter(Item.Parent).PlayerGui
        local g = PlayerGui.ScreenGui1.GetYourRingsReady.ImageLabel.OnesPlace.OnesPlaceImage.RingOnesPlaceValue
             if g.Value == 1 then
               g.Value = g.Value + 9 
   wait(0.0001) 
g.Value = g.Value + 1



end
end
end

script.Parent.Touched:connect(Touch)    

2 answers

Log in to vote
0
Answered by
farrizbb 465 Moderation Voter
7 years ago
Edited 7 years ago

you can have 0.0001 roblox has a wait limit just use wait() instead or renderstepped/heartbeat

If this worked please accept the answer.

0
Yeah it didn't work for me, sorry man. @farrizbb JoeRaptor 72 — 7y
0
any errors? farrizbb 465 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

I have no clue what your code is about, but I can suggest a lua feature for you.

for i = x,y,z do

end

"i" is like a counter.

"x" is your starting value,

"y" is the value you want to end at.

"z" is what you want to increase by.

So, if you want to start at 0 rings collected, you use "0" instead of x.

"z" is what you want it to increase by. In this case, 10.

Your "i" value is defined by whatever code you put between the "do" and "end."

So, your code inbetween the "i" and "end" keeps looping forever until "i" is at the value of your "y."

So, you can have code in there that when a player touches the part, it adds 10 to your "i" value and you could have the "y" at 10, and "z" at 10. So, when you touch the coin, it will set "i" to the value of 10, and will not increase anymore, since "i" is equal to "y," the ending value.

Then, when that loop is ended by the value being equal to "y," it will continue on to the code below the "end." So, at that point, you can have it add 10 to whatever Gui value that you have.

This is a little hard to explain, but here is a video for you.

https://www.youtube.com/watch?v=UsrtGk5E71w&t=264s

(This video actually helped me when I was starting out with the basics, I found it to be the most effective for explaining what a "for loop" is.)

Answer this question