#I don't know how to do a Medkit

1 messages · Page 1 of 1 (latest)

lilac comet
#

By some way idk how to make a Medkit on studio cuz I suck at it, so basically the thing is that the Medkit Script is always getting the diff of the Humanoid's Health and adding the diff to the Health.

Here it's the script.


local Handle = Tool.Handle

local Healing = false

local MaxHeal = 100

local StartFunction

Tool.ToolTip = MaxHeal.."/150"

local function Heal()
    local LocalPlayer = Tool:FindFirstAncestorWhichIsA"Player" or game:GetService"Players":GetPlayerFromCharacter(Tool.Parent)
    local Character = LocalPlayer.Character
    local Humanoid = Character:FindFirstChildWhichIsA"Humanoid"

    if Humanoid.Health < 100 and MaxHeal > 0 then
        
        print(Humanoid.Health)

        for i = 1, 0, -1 do
            print("Healing yourself "..i.."s..;")
            task.wait(1)
        end
        print("Healed yourself")
        
        local First = MaxHeal - Humanoid.Health
        local HealValue = First - MaxHeal
        
        Humanoid.Health -= HealValue
        
        print(HealValue)
        
        MaxHeal += HealValue
        
        Tool.ToolTip = MaxHeal.."/150"
        
        Healing = false
        if Humanoid.Health > 100 then
            print("Your HP is full")

            Healing = false
        end
        if MaxHeal <= 0 then
            print("No healing left")

            Healing = false
        end
    end
end

local function Activated()
    if not Healing then
        Healing = true

        StartFunction = task.spawn(Heal)

    else
        Healing = false
        task.cancel(StartFunction)
    end
end

Tool.Activated:Connect(Activated)```
lilac comet
#

Dude idfk

flint panther
#

This feels a bit too overcomplicated for such a simple thing.

lilac comet
#

Yea

#

The thing is

#

That the player can cancel the healing

flint panther
#

Hold on let me put it in proper syntax rq

#
local Tool = script.Parent

local Handle = Tool.Handle

local Healing = false

local MaxHeal = 100

local StartFunction

Tool.ToolTip = MaxHeal.."/150"

local function Heal()
    local LocalPlayer = Tool:FindFirstAncestorWhichIsA"Player" or game:GetService"Players":GetPlayerFromCharacter(Tool.Parent)
    local Character = LocalPlayer.Character
    local Humanoid = Character:FindFirstChildWhichIsA"Humanoid"

    if Humanoid.Health < 100 and MaxHeal > 0 then
        
        print(Humanoid.Health)

        for i = 1, 0, -1 do
            print("Healing yourself "..i.."s..;")
            task.wait(1)
        end
        print("Healed yourself")
        
        local First = MaxHeal - Humanoid.Health
        local HealValue = First - MaxHeal
        
        Humanoid.Health -= HealValue
        
        print(HealValue)
        
        MaxHeal += HealValue
        
        Tool.ToolTip = MaxHeal.."/150"
        
        Healing = false
        if Humanoid.Health > 100 then
            print("Your HP is full")

            Healing = false
        end
        if MaxHeal <= 0 then
            print("No healing left")

            Healing = false
        end
    end
end

local function Activated()
    if not Healing then
        Healing = true

        StartFunction = task.spawn(Heal)

    else
        Healing = false
        task.cancel(StartFunction)
    end
end

Tool.Activated:Connect(Activated)
#

so i can read properly

lilac comet
#

Oh u was talking abt that

flint panther
lilac comet
#

Damnit

#

Srry im new

#

Im like

flint panther
lilac comet
#

1 year on this

flint panther
#

But whats your issue here?

flint panther
#

😭

lilac comet
lilac comet
#

The thing is that the script gets the MaxHealing value and makes a Diff with the Humanoid currently Health

flint panther
#

Makes a difference with the Humanoid's current health?

lilac comet
#

What is a problem cuz if the MaxHealing = 50 and the Health = 30 the Humanoid will get the Diff of 50 with 30

#

That is 20

flint panther
#

Ok so

#

Overall the script works i assume right?

#

And your issue is just the calculations itself?

lilac comet
#

Yeah

#

It does

lilac comet
#

Im not that good with calculations

#

And logic

lilac comet
#

with the colors

#

its cool

flint panther
lilac comet
#

oh

#
print("wow")
#

thats awesome

flint panther
lilac comet
#

Basically

#

That

flint panther
#

Or are you trying to fully heal the player and then subtract MaxHealing with the humanoids health?

lilac comet
#

Oh yeah

#

That

scenic geyser
#

oh hi pcall

lilac comet
#

Make it like
MaxHealing = 50/100
Humanoid's Health = 30/100

Give everything

MaxHealing = 0/100
Humanoid's Health = 80/100

scenic geyser
#

why r u everywhere

#

:>

flint panther
lilac comet
scenic geyser
#

doesnt u jst do like for i= 1, max healing do...

flint panther
#

So basically, First Everytime you heal the player make sure you check if The humanoid's Health Is equals to the Humanoids MaxHealth during healing, and when you start healing you should subtract MaxHeal by 1 so when the while do statement breaks either due to Health being equals to MaxHeal or MaxHeal is 0 you would get a proper amount. easy as that!

scenic geyser
#

and why did u do for i =1,0,-1

lilac comet
#

its supposed to be i = 10, 0, -1

scenic geyser
#

why not for i = 1, maxhealth

flint panther
lilac comet
lilac comet
#

but i can make it

lilac comet
lilac comet
#

Like can u make it with script

#

im confuse

#

im tired

#

u know

scenic geyser
#

@flint panther dont

lilac comet
#

i know that this is not the best way to learn something

lilac comet
#

i will try to figure it out

flint panther
#

an example i can give as an s1 is like


local MaxHeal = 50
local Health = 30
local MaxHealth = 100


while Health ~= MaxHealth and MaxHeal ~= 0 do
      MaxHeal -= 1
      print(Health)
      print(MaxHeal)
    -- humanoid stuff here idk
end
lilac comet
#

i feel stupid like im using fucking modules and idk how to do this simple thing

hollow falconBOT
#
Program Output
/opt/wandbox/lua-5.4.7/bin/lua: prog.lua:7: syntax error near '-'

flint panther
#

oops

#

i forgot they dont support that

#

LOL

scenic geyser
#

i guess

lilac comet
#

for each second

#

it gives me 1 of health

flint panther
lilac comet
#

oh

#

well

#

isnt what i want to do but

flint panther
#

although its not for each second

lilac comet
#

alr

flint panther
#

its for each time it loops

lilac comet
#

ok

flint panther
#

if you do add as task.wait(1) then it will be for each second

#

🤷

lilac comet
#

ill try wait

scenic geyser
#

.

#

okay wait() works

#

i guess..

lilac comet
#

so its this right?

flint panther
flint panther
lilac comet
#

but isnt going to crash the script?

#

like time out

flint panther
#

No?

#

Why would it time out

#

you can add a task.wait() if you want

#

like just task.wait()

#

no number or sum

lilac comet
#

well i thought cuz it doesnt seem to be any task.wait or

flint panther
#

i think that would help

#

🤷

lilac comet
#

yea

#

i was just worried

#

but ill trust

flint panther
#

it should work just fine since its working on my shitty laptop

lilac comet
scenic geyser
lilac comet
#

i thought it would time out

#

well learned something

scenic geyser
lilac comet
#

also thx guys

flint panther
#

np

flint panther
#

glad i could help

lilac comet
#

im glad that someone saw my post

#

damn

#

its hard

scenic geyser
#

and repeat

#

like so much

lilac comet
flint panther
#

😭

#

I use RunService alot of times so its okay

scenic geyser
flint panther
#

i mostly just abuse Repeat heh

lilac comet
#

i used runserviced a lot of times

#

lrunserviced?

#

dude imt red

#

tire

#

tired

#

damn

flint panther
lilac comet
#

ill close this post and ill go sleep

flint panther
#

although i cant promise you the results would be clean

flint panther
#

Gn brodie

lilac comet
#

for those who want to see this are some models of the game

lilac comet
#

u too

#

and the peeps

#

!!!!!

#

bye bye

scenic geyser
#

theres uh