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

Anyone can help my make a coin that gives 10 extra max health?

Asked by
wswswff 39
1 year ago

i don't know how to get the player that touched the coin pls help

2 answers

Log in to vote
0
Answered by 1 year ago

100 health is automatic set I don't think you can give more than 100. Unless if the player is already harmed. Though you could change how much health something takes.

0
There is a property in the Humanoid called 'MaxHealth' ABDJackioZoAlt1 37 — 1y
0
Oh I didn't know that theking66hayday 841 — 1y
Ad
Log in to vote
0
Answered by
W0_0SH 65
1 year ago

Please note that this isn't a website to be asking for scripts/code.


Anyways it's fairly simple to make this type of script, first of all make sure to have a server script in Workspace or ServerScriptService and not a module/local script, then have a part in Workspace that will work as a coin.

local coin = game.Workspace.Coin -- The coin that will give +10 extra hp.
local debounce = false -- Making a debounce so that the coin function doesn't fire too many times. (Cooldown)
local debounceTime = 5 -- Time for the debounce (seconds), can be changed.

coin.Touched:Connect(function(hit) -- Function that fires every time the coin gets touched.

    if hit.Parent:FindFirstChild("Humanoid") and debounce == false then -- If the object that touched the coin has a Humanoid in it the block of code will run.
        local humanoid = hit.Parent:FindFirstChild("Humanoid") -- Making the humanoid a variable.
        debounce = true -- Starting the cooldown

        humanoid.MaxHealth = humanoid.MaxHealth + 10 -- Giving the Humanoid's max health + 10 health

        wait(debounceTime) -- The amount of time this block of code can be run again.
        debounce = false -- After the debounce time has ran out the debounce has been set to false meaning this block of code can be run again.
    end

end)
0
A very well explained script however with 1 slight misunderstanding, if the humands health is not 100 and it adds 10, in theory you will be giving more health to the humaoind to solve this on line 11 you have to do some arithmetic such as Humanoid.MaxHealth-Humanoid.Health and then use operators to check if that value is greater than 10 and if so just add 10 to health and if not subract it from 1 sne_123456 439 — 1y
0
*and if not subtract it from 10 and add that to the humanoid's maxhealth sne_123456 439 — 1y

Answer this question