#making a text lose 25 value per touch

222 messages · Page 1 of 1 (latest)

stark dove
#

local Debounce = false
local text = script.Parent.Part.SurfaceGui.TextLabel.Text

script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
if Debounce == false then
Debounce = true
print("hit")
script.Parent.Part.SurfaceGui.TextLabel.Text = text -25
wait(5)
print("no longer on debounce")
Debounce = false
end

end

end)

royal kraken
#

@stark dove what exactly are you trying to do?
Substract -25 from a value in the text?
Remove 25 characters from the text?

stark dove
#

value

#

it starts at 100

#

then goes down

royal kraken
#

Ah then do:

TextLabel.Text.."(Your text)"..value - 25
Example:
TextLabel.Text.."Cash:"..value-25
value = value - 25```
stark dove
royal kraken
stark dove
#

yup

royal kraken
#

Then do:

TextLabel.Text = tonumber(TextLabel.Text)-25```
crisp dewBOT
#

studio** You are now Level 6! **studio

royal kraken
#

@stark dove You understand what I'm doing or should I explain the code?

stark dove
#

never used it

blissful heath
blissful heath
stark dove
#

i dont know how it works fully

royal kraken
sick hare
stark dove
#

i see

#

ill add to to my notes thx

blissful heath
royal kraken
royal kraken
blissful heath
royal kraken
sick hare
#

personally i would have a separate variable for a number rather that converting the string into a number and then back into a string. The all you need to do is concatenate the number with the string at it is much simpler.

blissful heath
royal kraken
stark dove
sick hare
#

why are you telling that to me

stark dove
#

was planning to make it like health: 100

royal kraken
#

Then you have to use a variable.

royal kraken
#

As the OP might not know the term.

livid cave
stark dove
royal kraken
#

local number = 100
TextLabel.Text = "Health: "..number

sick hare
stark dove
#

its supposed to be for a wall breaking system

sick hare
stark dove
#

just not that far yet

sick hare
#

oh

sick hare
#

you could always add a number value inside the wall

royal kraken
sick hare
#

or even an attribute

royal kraken
sick hare
#

why?

#

ok

stark dove
#

im friends with alot of known devs but they refuse to teach me so

#

🤷‍♂️

sick hare
#

a number value is an object that can be added inside the wall

stark dove
sick hare
#

it has a property inside it called "Value"

stark dove
#

just not sure how it works entirely

sick hare
#

you can set the value to a number

#

which could represent the wall's health

stark dove
crisp dewBOT
#

studio** You are now Level 3! **studio

stark dove
#

could you make an example?

sick hare
#

or you could use an attribute inside the wall and make that a number value and that could represent hp instead

dark terrace
sick hare
dark terrace
stark dove
sick hare
stark dove
#

thanks for the help

sick hare
#

@ me if you need more help

stark dove
#

only how to use it

sick hare
#
instance:SetAttribute("HP", instance:GetAttribute("HP")-1)
#

first parameter is the name of the value

#

and the second parameter is the actual value

stark dove
#

thanks

#

im not sure what does instance do?

#

i omlu kmoe og it as instance.new

#

only know of it

royal kraken
# stark dove im not sure what does instance do?

Instance isn’t the thing that should actually be there. An instance is everything you can see in the explorer window.
A Humanoid is an instance.
A TextLabel is an instance.
A Part (referred to as wall by Majestic) is an instance.
Etc.

stark dove
royal kraken
#

I would recommend checking out a tutorial on YouTube, as they can explain it better.

stark dove
#

wasted so much time on them and learned nothing

#

half of them dont know what theyre saying either

royal kraken
#

Alvin blox makes good ones.

#

Start with his beginners series.

stark dove
#

theyre mad lengthy

royal kraken
stark dove
royal kraken
stark dove
#

i watched like 2

royal kraken
#

The advanced are to hard to understand for a beginner.

stark dove
#

both were kinda just s tuff i alr knew

#

ill give em a shot

royal kraken
#

Then watch the next one.

stark dove
#

my friend is friends with him so

royal kraken
#

If you have questions feel free to ping me.

stark dove
#

hes been reccomending too

stark dove
eternal acorn
royal kraken
stark dove
#

ill go watch his vids now tho

eternal acorn
#

No just think about it kogically

#

Lets say you have the value at 100 right

#

What your code does is if you hit, the text becomes value-25 = 75

#

Now if u hit again.. it becomes value-25 = 75 again

#

U dont change the value soo

#

Ud either change the value itself or the 25 that u are subtracting by, by making it 25n

#

The later is harder tho

eternal acorn
#

Ud ideally want to subtract 25 from the value u are basing the HP or whatever from, then update the text

#

But if its something that u dont want to go below 0 u should also include a check for whether it wont become <0

eternal acorn
stark dove
eternal acorn
#

Do yk variables?

stark dove
#

i combined a kill break script im very familiar with alongside a debounce system i like

stark dove
eternal acorn
stark dove
eternal acorn
#

Yeah so what id do is make a health (or whatever) variable that would be a number and id decrease that number by 25 each time u wanted to decrease that

#

If u didnr know u can put variables into strings by so called concatenation

eternal acorn
#
local foo = 4
print("the variable is equal to " .. foo)

>> the variable is equal to 4
#

Make sure not to put the var name in quotes as that would turn it into a literal string, so it would not get the value but rather the text u named it as

eternal acorn
stark dove
crisp dewBOT
#

studio** You are now Level 4! **studio

eternal acorn
#

it shouldve

#

oh right u cant do what u did with the text variable

stark dove
#

oh

eternal acorn
#

basically what u did with the text variable is u copied the current text into it (Text is a property like health for humanoids)

#

what u want is a path variable so u wanna remove the .Text from the text variable

#

and u wanna do something like text.Text

stark dove
#

righttt

eternal acorn
#

or rename it to something better ideally (the variable)

#

for better readability

#

but yeah thats the issue

stark dove
#

it works

#

thanks man

eternal acorn
#

yeah np

stark dove
#

ill try to make the limit 0 now

eternal acorn
#

yeah gl, feel free to ask if u dont know

stark dove
#

could i add you if u dont mind?

eternal acorn
#

i mean sure

#

but honestly try to problem solve on your own first if u dont cuz it really helps in the long run

#

its practically impossible at first but necessary to be good

eternal acorn
#

especially with things like this where u just didnt know how the code would work

#

but yeah

#

gl with coding :D

stark dove
#

im trynna make it out here despite being stupid

eternal acorn
#

thats why coding is so well paid, cause its not easy :)

stark dove
#

alot of my friends are high profile devs so its kinda hard to compare lol

eternal acorn
# stark dove feels like it

if u were learning a new language with a different logic u also wouldnt be able to do it fluently until you used it for hundreds or thousands of hours, thats what coding is

eternal acorn
#

u dont know what theyve been through, its just a good demotivator

#

trust me lol i know it

stark dove
#

thanks for the motivation sunglasses

eternal acorn
#

yeah no worries

#

feel free to dm me if u need to, my dms are always open

stark dove
eternal acorn
#

i may not respond soon but i will eventually

stark dove
eternal acorn
#

especially once you learn the coding thinking learning other languages is so much easier

#

it took me about 2 years to learn python on a usable level, lua took me 50 minutes

#

theyre roughly similar in difficulty

eternal acorn
# stark dove 50`?

yeah cause i already knew how to use everything, i just needed the syntax

stark dove
#

one of my dreams is to get to be point of being able to do commisions

eternal acorn
#

the syntax is not even that hard if u think about it, especially not since both lua and python are in the nice family with no {}; chars

stark dove
#

been a dream since i was a small child lmao

eternal acorn
#

its the hardest near the end tbh

#

when u already "know" everything in theory but you cant really use it practically

stark dove
#

if u know what it does u just gotta combine it

eternal acorn
#

its like when u learn a new equation in math but u dont know where to apply it

#

its the hardest to learn where to use the stuff uve learnt

#

and of course theres things that u are using right now that have other use cases than you can think of because u dont need it rn so yea

#

like the level between being okay and good

eternal acorn
#

thats only learnt by practice

#

but yeah gl again, ill go now

stark dove
eternal acorn
#

i turned into a perfectionist and i focus on one small thing too much to get it be faster by a little bit, which demotivates me cuz i seemingly make no progress

stark dove
#

also i made it work

#

already

eternal acorn
#

thats one of those terrible habits u have to fight later on when u learn optimization

eternal acorn
stark dove
eternal acorn
#

gtg

stark dove
stark dove
#

goodbye

#

nvm doesnt really work

stark dove
#

@royal kraken happy birthday